status.page.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }
  29. /**
  30. * Prepares variables for a custom entity type creation list templates.
  31. *
  32. * Default template: status-content-add-list.html.twig.
  33. *
  34. * @param array $variables
  35. * An associative array containing:
  36. * - content: An array of status-types.
  37. *
  38. * @see block_content_add_page()
  39. */
  40. function template_preprocess_status_content_add_list(&$variables) {
  41. $variables['types'] = array();
  42. $query = \Drupal::request()->query->all();
  43. foreach ($variables['content'] as $type) {
  44. $variables['types'][$type->id()] = array(
  45. 'link' => Link::fromTextAndUrl($type->label(), new Url('entity.status.add_form', array(
  46. 'status_type' => $type->id()
  47. ), array('query' => $query))),
  48. 'description' => array(
  49. '#markup' => $type->label(),
  50. ),
  51. 'title' => $type->label(),
  52. 'localized_options' => array(
  53. 'query' => $query,
  54. ),
  55. );
  56. }
  57. }