Domanda

I have created a module called custom_views. Its directory is: sites/all/modules/custom_views

In the directory there are two files called:

custom_views.info

and

custom_views.module

Here is the code for the .info file:

; Custom views created by me
name = Custom Views
description = Module to allow custom view development
package = Custom Views
core = 7.x
php = 5.2

Here is the code for the .module file:

<?php
  function custom-views_views_default_views() {
  $views = array();
  $path = drupal_get_path('module', 'custom_views') . '/views';
  $files = drupal_system_listing('.inc$', $path, 'name', 0);
  foreach($files as $file) {
  include_once $file->filename;
  }
return $views;
}
?>

For some reason it will not allow me to enable it in the modules list and I cannot figure out why... I have also tried clearing my cache. Does anyone have any ideas?

È stato utile?

Soluzione

The function name is wrong as mentioned in other answers. The hyphen should be replaced with an underscore.

Double check the module location

It should reside in one of the following folders

  • /sites/all/modules/your_module
  • /sites/domain.com/modules/your_module
  • /sites/all/modules/your_module

Info File

Only Name, Description and Core are required in your info file. Start by removing everything except those values.

name = Custom Views
description = Module to allow custom view development
core = 7.x

The PHP version you specified is a minimum PHP version required to run the module. Sounds obvious but have you checked to see if you are running >= 5.2

Check the permissions of the module folder and the .info file too.

When Drupal looks for modules, it uses file_exists() on the .info file which will return false if the file does not exist, or it cannot access it due to permissions or incorrect ownership.

The ownership of the file is of key importance too. Check the owner of the info file matches one of a module which works.

Encoding

Some encoding can prevent the .info file being read. UTF8 without BOM should typically be read successfully.

Altri suggerimenti

Follow documentation here

https://drupal.org/node/1075072

where you see you should have your well-written module even without the .module file

have fun!

Not sure this will help your module to appear on the module page, but I think your function should be called custom_views_views_default_views() rather than custom-views_views_default_views()

i.e. underscore not dash in function name

Maybe Drupal only lists modules with at least one valid function

Since you have tried all the other suggested issues, try removing the closing php tag.

Not sure if it would be causing your particular problem but it is recommended you don't use closing php tags in your module files as you can run into problems if there is whitespace after the closing tag.

There could also possibly be problems with the other files you are including.

What if you comment out the function you have in the .module file and try to install it. If it works then you have a problem in that function or in the files it includes.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top