status.page.inc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * Contains status.page.inc.
  5. *
  6. * Page callback for Status entities.
  7. */
  8. use Drupal\Core\Render\Element;
  9. use Drupal\Core\Link;
  10. use Drupal\Core\Url;
  11. /**
  12. * Prepares variables for Status templates.
  13. *
  14. * Default template: status.html.twig.
  15. *
  16. * @param array $variables
  17. * An associative array containing:
  18. * - elements: An associative array containing the user information and any
  19. * - attributes: HTML attributes for the containing element.
  20. */
  21. function template_preprocess_status(array &$variables) {
  22. // Fetch Status Entity Object.
  23. $status = $variables['elements']['#status'];
  24. // Helpful $content variable for templates.
  25. foreach (Element::children($variables['elements']) as $key) {
  26. $variables['content'][$key] = $variables['elements'][$key];
  27. }
  28. $variables['content']['status_message'] = $status->getMessage()->view();
  29. }
  30. /**
  31. * Prepares variables for a custom entity type creation list templates.
  32. *
  33. * Default template: status-content-add-list.html.twig.
  34. *
  35. * @param array $variables
  36. * An associative array containing:
  37. * - content: An array of status-types.
  38. *
  39. * @see block_content_add_page()
  40. */
  41. function template_preprocess_status_content_add_list(&$variables) {
  42. $variables['types'] = array();
  43. $query = \Drupal::request()->query->all();
  44. foreach ($variables['content'] as $type) {
  45. $variables['types'][$type->id()] = array(
  46. 'link' => Link::fromTextAndUrl($type->label(), new Url('entity.status.add_form', array(
  47. 'status_type' => $type->id()
  48. ), array('query' => $query))),
  49. 'description' => array(
  50. '#markup' => $type->label(),
  51. ),
  52. 'title' => $type->label(),
  53. 'localized_options' => array(
  54. 'query' => $query,
  55. ),
  56. );
  57. }
  58. }