permission doesnt show up in my permissions page - drupal

I have installed Drupal 7.34 in my computer and created a module named "mymodule". I already created successfully the file mymodule.info and mymodule.module. Below are their following contents:
[mymodule.info]
; $Id$
name = mymodule
description = Alyssa Gono's first module.
core = 7.x
package = Example
[mymodule.module]
<?php
// $Id$
/**
* #file
* Main module file for mymodule Module.
*/
/**
* Implementation of hook_permission().
*
* This function takes 0 arguments, and returns an array of permissions defined by our module. Our permissions are automatically made avilable
* under admin/user/permissions.
*/
function mymodule_permission() {
return array(
'administer mymodule' => array(
'title' => t('Administer mymodule'),
'description' => t('Perform administration tasks for mymodule.'),
),
);
}
But when I navigate to Permissions Page, to find out if my hook permissions was implemented successfully, the permission I made seems not to show up. where did I go wrong?

Your code looks fine. Maybe it is a cache issue. Try clearing the cache from ?q=admin/config/development/performance and see if the permission is shown.

Related

Drupal 8.6 Commerce: in .install file without module_uninstall() remove tables from database. Why?

When uninstall module then why delete all table from database without module_uninstall() function in .install file.
Also, why create table without module_install() function
.install file code is only:
function commerce_quickpay_schema() {
$schema['webc_crypto_meta'] = [
'description' => 'Custom Cryptography Meta',
'fields' => [...],
'primary key' => ['wcm_id'],
];
$schema['webc_crypto_payment'] = [
'description' => 'Custom Cryptography Payment',
'fields' => [...],
'primary key' => ['wcp_id'],
];
return $schema;
}
Also, please, CREATE TABLE IF NOT EXISTS condition in .install file.
This is how it behaves, the tables defined in hook_schema will be created or removed from the database when the module is installed or uninstalled, the hook_install() or hook_uninstall() hooks should be used when you want to do something extra.
It is simply assumed that the database schema should be removed when a module is uninstalled and come back when installed, if you think about it, it makes perfect sense.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%21database.api.php/function/hook_schema/8.7.x
"The tables declared by this hook will be automatically created when
the module is installed, and removed when the module is uninstalled.
This happens before hook_install() is invoked, and after
hook_uninstall() is invoked, respectively."

Drupal - best practice for database settings

In Drupal, what is the best practice for configuring database settings (database, username, password, host, etc.)?
In sites/default/default.settings.php it states the following:
/**
* Database settings:
*
* The $databases array specifies the database connection or
* connections that Drupal may use. Drupal is able to connect
* to multiple databases, including multiple types of databases,
* during the same request.
*
* One example of the simplest connection array is shown below. To use the
* sample settings, copy and uncomment the code below between the #code and
* #endcode lines and paste it after the $databases declaration. You will need
* to replace the database username and password and possibly the host and port
* with the appropriate credentials for your database system.
*
* The next section describes how to customize the $databases array for more
* specific needs.
*
* #code
* $databases['default']['default'] = array (
* 'database' => 'databasename',
* 'username' => 'sqlusername',
* 'password' => 'sqlpassword',
* 'host' => 'localhost',
* 'port' => '3306',
* 'driver' => 'mysql',
* 'prefix' => '',
* 'collation' => 'utf8mb4_general_ci',
* );
* #endcode
*/
$databases = array();
But what if your development environment and your production environment will have different database settings?
Drupal supports multisites. You can use that for multiple configurations for development, staging and production.
Create a folder in the sites folder with the name of your development, staging and production domains and each of them will have their own settings.php file which in turn means they will have separate database connection configurations. Drupal will auto-select the correct folder depending on the domain that is currently being used.
Usually I setup three folders:
development.myproject.com
staging.myproject.com
myproject.com (production)
Configuring sites.php is optional if the folders you create are exactly the domain name. You can configure sites.php if you want to access via a path (e.g. myproject.com/devel).
Some more info in the Drupal docs.

Virtual Filesystem for PHPUnit tests in Laravel 5.4

i'm having a bit of a problem with my PHPUnit integration tests, i have a method which handles a form upload for a video file as well as a preview image for that video.
public function store($request)
{
/** #var Video $resource */
$resource = new $this->model;
// Create a new Content before creating the related Photo
$contentRepo = new ContentRepository();
$content = $contentRepo->store($request);
if($content->isValid()) {
$resource->content_id = $content->id;
$directory = 'frontend/videos/assets/'.date("Y").'/'.date('m').'/'.time();
\File::makeDirectory($directory, 0755, true);
$request->video->move($directory.'/', $request->video->getClientOriginalName());
$resource->video = '/'.$directory.'/'.$request->video->getClientOriginalName();
$request->preview_image->move($directory.'/', $request->preview_image->getClientOriginalName());
$resource->preview_image = '/'.$directory.'/'.$request->preview_image->getClientOriginalName();
$resource->highlighted = intval($request->input('highlighted') == 'on');
$resource->save();
return $resource;
}
else {
return $content;
}
}
The important part to keep is the $request->video->move() call which i probably need to replace in order to use Virtual Filesystem.
and then the test
public function testVideoUpload(){
File::put(__DIR__.'/frontend/videos/assets/image.mp4', 'test');
$file = new UploadedFile(__DIR__.'/frontend/videos/assets/image.mp4', 'foofile.mp4', 'video/mp4', 100023, null, $test=true);
File::put(__DIR__.'/frontend/images/assets/image.jpg', 'test');
$preview = new UploadedFile(__DIR__.'/frontend/images/assets/image.jpg', 'foofile.jpg', 'image/jpeg', 100023, null, $test=true);
$this->post('/admin/videos', [
'title' => 'My Video #12',
'description' => 'This is a description',
'actors' => [$this->actor->id, $this->actor2->id],
'scenes' => [$this->scene->id, $this->scene2->id],
'payment_methods' => [$this->paymentMethod->id],
'video' => $file,
'preview_image' => $preview
])->seeInDatabase('contents', [
'title' => 'My Video #12',
'description' => 'This is a description'
]);
}
As you can see, i need to create a dummy file in some local directory and then use that in the HTTP request to the form's endpoint, then after that, that file would be moved and i need to delete the created folder and the new moved file... it's an authentic mess.
As such i want to use Virtual Filesystem instead, but i have no idea how to set it up in this particular case, i've already downloaded a package and set it up, but the questions are, first, which package have you used/recommend and how would you tweak the class and the test to support the Virtual Filesystem? Would i need to switch over to using the Storage facade instead of the $request->video->move() call? If so how would that be done exactly?
Thank you in advance for your help
I couldn't figure out the VFS system, however i do have somewhat of an alternative that's still kinda messy but gets the job done.
Basically i set up two methods on my PHPUnit base class to setup and teardown the temp folders i need on any test that requires them, because i'm using Database Transactions the files get deleted on every test run and i need to create new dummy files every time i run the test.
So i have two methods setupTempDirectories and teardownTempDirectories which i will call at the beginning and at the end of each test that requires those temporary directories.
I put my temp files in the Storage directory because sometimes i run my tests individually through PHPStorm and the __DIR__ command gets messed up and points to different directories when i do that, i also tried __FILE__ with the same result, so i just resorted to using Laravel's storage_path instead and that works fine.
Then that leaves the problem of my concrete class which tries to move files around and create directories in the public folder for them... so in order to fix that i changed the code to use the Storage facade, then i Mock the Storage facade in my tests
So in my concrete class
$directory = 'frontend/videos/assets/'.date("Y").'/'.date('m').'/'.time();
Storage::makeDirectory($directory, 0755, true);
Storage::move($request->video, $directory . '/' . $request->video->getClientOriginalName());
$resource->video = '/'.$directory.'/'.$request->video->getClientOriginalName();
Storage::move($request->preview_image, $directory . '/' . $request->preview_image->getClientOriginalName());
$resource->preview_image = '/'.$directory.'/'.$request->preview_image->getClientOriginalName();
And then in my test i mock both the makeDirectory and the move methods like such
// Override the Storage facade with a Mock version so that we don't actually try to move files around...
Storage::shouldReceive('makeDirectory')->once()->andReturn(true);
Storage::shouldReceive('move')->twice()->andReturn(true);
That makes my tests work and does not actually leave files behind after it's done...i hope someone has a better solution but for the time being this is what i came up with.
I was actually trying to use VFS but it never worked out... i keep getting errors that the original file in the storage directory is not found even though it's right there...
I'm not even sure the Storage facade was using VFS in the background to begin with even though it should...

How do i check if a user is accessing a particular module in drupal

I do have a list of modules in D6.Is there any way by which i could probably find which module the current user is accessing.If i have a module named X and a function named Y.If a user is using the function Y could i check if the X module is being accessed by the user..??
You can add a watchdog call to the function in question. Monitor access in-site on the reports page then.
Here is an example:
global $user;
watchdog("Access Logging",
"Access to %func in %file by %user",
array("%func" => __FUNCTION__,
"%file" => __FILE__,
"%user" => $user->name),
WATCHDOG_NOTICE);

Drupal node_type_get_type() and hook_uninstall()

I have a module job_post which installs job_post content type.
In this module I have hook_unistall() which calls for node_type_delete() function which removes my content type.
After unistalling process I have errors from Drupal's core module comment which fires from node_type_delete() after module_invoke_all('node_type_delete', $info).
Error is the following and repeats 8 times (because of the loop in comment_node_type_delete()):
Notice: Trying to get property of non-object in comment_node_type_delete()
(line 343 of ....\comment.module).
I have this error because $info variable in node_type_delete() function is false.
My question is, why when my module is installed and when I'm printing var_dump(node_type_get_type('job_post')) on any page, I have an object, but when I'm trying to print the same code in my unistall function I get false and this error?
job_post.install
/**
* Implements hook_install().
*/
function job_post_install() {
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['job_post']);
$body_instance = field_info_instance('node', 'body', 'job_post');
$body_instance['type'] = 'text_summary_or_trimmed';
field_update_instance($body_instance);
}
/**
* Implements hook_uninstall().
*/
function job_post_uninstall() {
$instances = field_info_instances('node', 'job_post');
foreach ($instances as $instance_name => $instance) {
field_delete_instance($instance);
}
// Force rebuild of the node type cache
// as Clive suggested didn't help
// _node_types_build(TRUE);
node_type_delete('job_post');
field_purge_batch(1000);
}
job_post.module
/**
* Implements hook_node_info() to provide our job_post type.
*/
function job_post_node_info() {
return array(
'job_post' => array(
'name' => t('Job Post'),
'base' => 'job_post',
'description' => t('Use this content type to post a job.'),
'has_title' => TRUE,
'title_label' => t('Job Title'),
'help' => t('Enter the job title and job description')
)
);
}
/**
* Implement hook_form() with the standard default form.
*/
function job_post_form($node, $form_state) {
return node_content_form($node, $form_state);
}
Note: This module example was taken from Pro Drupal 7 Development book (page 141) with minor changes and it was given errors even with original.
Hi by referring to documentation an core modules of Drupal 7. There is a usage problem.
hook_node_info defines a content type automatically. The content types which are created in this way, uninstalled-disable automatically.
Core blog module defines hook_node_info but does not operate any node_type_delete on hook_uninstall
http://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_node_info/7
When you call node_type_delete('job_post'); on hook_uninstall, node type info has already gone. Because of that comments module raises error.
Normally you should only remove any data related to your content type. And let the rest to be done by core.
Additionally if you really want create/delete your content type, you may not use hook_node_info. You can manually create/delete content type on install/uninstall hook.
Sample uninstall here:
http://public-action.org/content/drupal-7-field-api-drupal-7-adding-custom-content-type-custom-fields-field-api
It seems like the node type cache hasn't been built fully for some reason, try forcing the rebuild before you call node_type_delete() and all node types should be made available:
// Force rebuild of the node type cache
_node_types_build(TRUE);
// Delete our content type
node_type_delete('job_post');

Resources