I am new to Drupal 8 and it is hard to comprehend the documentation. I am required to make a custom module. I came across examples in creating custom modules, but I am having difficulty in making the correct return type. For example, consider the code snippet take from doc:
<?php
/**
* @file
* Contains \Drupal\hello_world\Controller\HelloController.
*/
namespace Drupal\hello_world\Controller;
use Drupal\Core\Controller\ControllerBase;
class HelloController extends ControllerBase {
public function content() {
return array(
'#type' => 'markup',
'#markup' => $this->t('Hello, World!'),
);
}
}
In this example, the controller is called when some page (defined in route) is visited. In this case an array is returned with #type and #markup, whose definition I cannot find anywhere. Similary consider another example:
<?php
namespace Drupal\acme\Controller;
use Drupal\Core\Controller\ControllerBase;
class DefaultController extends ControllerBase {
public function hello($name) {
// the {name} in the route gets captured as $name variable
// in the function called
return [
'#theme' => 'hello_page',
'#name' => $name,
'#attached' => [
'library' => [
'acme/acme-styles', //include our custom library for this response
]
]
];
}
}
In this case, the return type is #theme, #name and #attached. These two code clearly shows different return type. As a beginner, I am having difficulty in understanding what to return from function as I cannot see those definitions in the documentation of ControllerBase class.
Where in the documentation are these tags defined and how do I use them in different scenarios? Thanks.