Drupal

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

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, 
  ];
}
続きを読む

Drupal 8: How to Translate Your Custom Block Fields

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.

続きを読む
Subscribe to Drupal