ctools.module 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Implements hook_theme().
  4. */
  5. function ctools_theme($existing, $type, $theme, $path) {
  6. return [
  7. 'ctools_wizard_trail' => [
  8. 'variables' => [
  9. 'wizard' => NULL,
  10. 'cached_values' => [],
  11. 'trail' => [],
  12. 'divider' => ' » ',
  13. 'step' => NULL,
  14. ],
  15. ],
  16. 'ctools_wizard_trail_links' => [
  17. 'variables' => [
  18. 'wizard' => NULL,
  19. 'cached_values' => [],
  20. 'trail' => [],
  21. 'divider' => ' » ',
  22. 'step' => NULL,
  23. ],
  24. ],
  25. ];
  26. }
  27. function template_preprocess_ctools_wizard_trail(&$variables) {
  28. /** @var $wizard \Drupal\ctools\Wizard\FormWizardInterface|\Drupal\ctools\Wizard\EntityFormWizardInterface */
  29. $wizard = $variables['wizard'];
  30. $cached_values = $variables['cached_values'];
  31. $trail = $variables['trail'];
  32. $variables['step'] = $wizard->getStep($cached_values);
  33. foreach ($wizard->getOperations($cached_values) as $step => $operation) {
  34. $trail[$step] = !empty($operation['title']) ? $operation['title'] : '';
  35. }
  36. $variables['trail'] = $trail;
  37. }
  38. function template_preprocess_ctools_wizard_trail_links(&$variables) {
  39. /** @var $wizard \Drupal\ctools\Wizard\FormWizardInterface|\Drupal\ctools\Wizard\EntityFormWizardInterface */
  40. $wizard = $variables['wizard'];
  41. $cached_values = $variables['cached_values'];
  42. $trail = $variables['trail'];
  43. $variables['step'] = $wizard->getStep($cached_values);
  44. foreach ($wizard->getOperations($cached_values) as $step => $operation) {
  45. $parameters = $wizard->getNextParameters($cached_values);
  46. // Override step to be the step we want.
  47. $parameters['step'] = $step;
  48. $trail[$step] = [
  49. 'title' => !empty($operation['title']) ? $operation['title'] : '',
  50. 'url' => new \Drupal\Core\Url($wizard->getRouteName(), $parameters),
  51. ];
  52. }
  53. $variables['trail'] = $trail;
  54. }
  55. function ctools_condition_info_alter(&$definitions) {
  56. // If the node_type's class is unaltered, use a custom ctools implementation.
  57. if (isset($definitions['node_type']) && $definitions['node_type']['class'] == 'Drupal\node\Plugin\Condition\NodeType') {
  58. $definitions['node_type']['class'] = 'Drupal\ctools\Plugin\Condition\NodeType';
  59. }
  60. }