All

Drupal 8: How to Return a Markup incl. a URL link

Submitted by admin on Sun, 03/04/2018 - 01:17

Drupal 8 provides a useful helper funciton $entity->toLink(..). You must return it by converting to a string by using ->toString() at the end.
public function foo(Request $request = NULL) {

$id = $request->get('id'); // from query string
$entity = YourEntity::load($id);

$message = $this->t('Check at @url.', [
'@url' => $entity->toLink('<TEXT_TO_LINK_HERE>', 'edit-form')->toString(),
]);

return [
'#type' => 'markup',
'#markup' => $message,
];
}

Tags

Drupal 8: How to Display Checkbox in List View

Submitted by admin on Sun, 03/04/2018 - 01:20

For example shown below, ['data'] requires after ['active'] like ['active']['data'].
public function buildRow(EntityInterface $entity) {

$row['active']['data'] = [ // @IMPORTANT: add ['data'] here
'#type' => 'checkbox',
'#default_value' => (bool) $entity->isActive(),
'#checked' => (bool) $entity->isActive(),
'#attributes' => ['disabled' => 'disabled'],
'#disabled' => TRUE,
];

return $row + parent::buildRow($entity);
}

Tags

PHP: How to Install Zend Framework v1 (zf1)

Submitted by admin on Tue, 02/20/2018 - 22:31

You can install Zend Framework v2 as follows:
composer require zendframework/zendframework

However Zend Framework v1 has already been obsolete, therefore when you want to install it manually, you need to download the library from GitHub, and copy (move) to your application directory.

Download Zend Framework v1 library from GitHub (Note that the following example is aimed for minimal package. If you want to install the full package, delete a -minimal portion. Also note that the following command line is just one line, even though it has new lines.)

Tags

Drupal 8: How to Translate Your Custom Block Fields

Submitted by admin on Tue, 01/30/2018 - 15:11

If you want to create a module that provides your custom block(s) in Drupal 8, for instance, you can only write two source codes such as my_custom_block.info.yml and MyCustomBlock.php. However how can you make custom configuration fields on your custom block translatable? The answer is to add one additional file my_custom_block.yml as a schema file.

Tags