Drupal

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

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

Drupal 8: How to Handle Errors After Updating Core or Modules

Submitted by admin on Wed, 09/21/2016 - 14:08

I think we should doubt cache since Drupal 8 aggressively uses cache-backend mechanism. If you encounter a fatal error or WSOD (White Screen of Death), check the following items.

Check error logs at /var/log/apache2/error.log

sudo tail -f /var/log/apache2/error.log

Configuration | Performance - Check off Aggregate CSS files and Aggregate JavaScript files

Configuration | Performance - Clear all caches

Rebuild cache from Drush

# Move to the directory where Drupal 8 is installed by using cd command,
sudo drush -l <YOUR_SITE_URL> cr

Tags

Drupal 7: How to Add Bootstrap Multi-level Dropdown Submenu

Submitted by admin on Mon, 04/11/2016 - 10:57

Download and install a Bootstrap theme. Modify the following at
vi bootstrap/templates/menu/system/form-element.func.php

 
/**
* Overrides theme_form_element().
*/
function bootstrap_form_element(&$variables) {
$element = &$variables['element'];
$name = !empty($element['#name']) ? $element['#name'] : FALSE;
$type = !empty($element['#type']) ? $element['#type'] : FALSE;
$checkbox = $type && $type === 'checkbox';
$radio = $type && $type === 'radio';

Tags