block_content.pages.inc 984 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * @file
  4. * Provides page callbacks for custom blocks.
  5. */
  6. use Drupal\Core\Link;
  7. use Drupal\Core\Url;
  8. /**
  9. * Prepares variables for a custom block type creation list templates.
  10. *
  11. * Default template: block-content-add-list.html.twig.
  12. *
  13. * @param array $variables
  14. * An associative array containing:
  15. * - content: An array of block types.
  16. *
  17. * @see block_content_add_page()
  18. */
  19. function template_preprocess_block_content_add_list(&$variables) {
  20. $variables['types'] = [];
  21. $query = \Drupal::request()->query->all();
  22. foreach ($variables['content'] as $type) {
  23. $variables['types'][$type->id()] = [
  24. 'link' => Link::fromTextAndUrl($type->label(), Url::fromRoute('block_content.add_form', ['block_content_type' => $type->id()], ['query' => $query]))->toString(),
  25. 'description' => [
  26. '#markup' => $type->getDescription(),
  27. ],
  28. 'title' => $type->label(),
  29. 'localized_options' => [
  30. 'query' => $query,
  31. ],
  32. ];
  33. }
  34. }