Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Drupal Basics Writing Modules Your First Module

Gina Mills
Gina Mills
15,668 Points

Having issues with modules in drupal 8

Hi there - I've ended up using drupal 8 and so late into the course I'd prefer to keep using it. My module isn't working and I think it's most likely because I'm using Drupal 8, I've noticed that it needs a .info.yml file as well now but are there other changes in the php code or files I need to do to make this work? When I go to the link the module should be at it says "page not found" - thanks!

Gina Mills
Gina Mills
15,668 Points

for the sake of it here is the code

<?php

function greeting_menu() {  
    $items = array();
    $items['hello_friend'] = array(
        'title' => "Hello Friend!",
        'page callback' => 'say_hello',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM, 
    );
    return $items;
}

function say_hello() {
    return '<p>Hello my dear friend!</p>';
}

1 Answer

Hi. Check this link for info on how to convert the .info file into .yml for Drupal 8

https://www.drupal.org/docs/8/converting-drupal-7-modules-to-drupal-8/step-1-convert-mymoduleinfo-to-mymoduleinfoyml

I just use the following greetings.info.yml text:

name: Greetings
type: module
description: 'Provides a greeting'
package: Greetings tool suite
# core: 8.x
version: '8.x-1.0'
core: '8.x'
project: 'greetings'