0

Playing around with Drupal 8 and trying to create a custom module with a custom block:

I have a module.info.yaml file:

name: Custom Module
description: Description Here
package: Custom Module
type: module
core: 8.x

dependencies:
  - block

I have a src/Plugin/CustomBlock/CustomBlock.php file:

<?php

/**
 * Provides a 'Custom' Block
 *
 * @Block(
 *   id = "custom_block",
 *   admin_label = @Translation("Custom Block"),
 * )
 */

namespace Drupal\custom_block\Plugin\Block;

use Drupal\Core\Block\BlockBase;

class CustomBlock extends BlockBase {
  /**
   * {@inheritdoc}
   */
  public function build() {
    return array(
      '#markup' => $this->t('Hello, World!'),
    );
  }
}

The module is in /modules/custom/module. I have installed contrib modules in /modules/contrib with no issue.

If I go to the Extend page, my module is not listed.

Please let me know what I am missing here?

0
10

Typo on the module file name:

module.info.yaml

Should be

module.info.yml
1
  • Yep. D8 only requires .info.yml file in order to show up on the module's page.
    – AjitS
    Apr 8 '16 at 2:47
1

EDIT: I think I'm mistaken, sorry! For now, just putting this note into the comment -- when I have a more definitive answer, I'll update again.


FWIW, with Drupal core 8.7.7, our custom module didn't show on /admin/modules until I added the new core_version_requirement key to mymodule.info.yml, i.e.

core_version_requirement: '^8'

For now, I kept the old core: 8.x line in there, too, b/c I'm unsure whether it's good/bad/neutral to have both -- I think it's still being decided, tbh. Speaking of which, there's a change record and a ton of issue threads (active and completed) you can check out to learn more, if you wish:

  • 8.7.7 release notes excerpt:

    Core versioning support in *.info.yml files
    Drupal 8.7.7 introduces a new core_version_requirement key to *.info.yml files, allowing contributed modules to specify specific versions for Drupal core compatiblity, as well as to indicate that they are compatible with both Drupal 8 and the forthcoming Drupal 9 release. See the change record for more details.

  • Change record (mentioned in that excerpt)

  • Main issue thread for this functionality -- plus all the related issues listed on the right.
0

Also make sure your web server has file permissions to the module.

-1

Web server permissions may indeed be the issue, especially if everything else seems fine.

https://www.drupal.org/docs/security-in-drupal/securing-file-permissions-and-ownership

I constantly run this set of commands because my Windows ftp client sets ownership to my-user:my-user. Your web server might not be apache.

(requires a symlink to your drupal root folder from the server root)

cd /drupal9
sudo chown -R my-user:apache .
sudo find . -type d -exec chmod 750 '{}' \;
sudo find . -type f -exec chmod 640 '{}' \;
cd web/sites
sudo find . -type d -name files -exec chmod 770 '{}' \;
for d in ./*/files
do
   sudo find $d -type d -exec chmod 770 '{}' \;
   sudo find $d -type f -exec chmod 660 '{}' \;
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.