ouatt_admin.module 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * @file
  4. * Contains admin_menus.module.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. use Drupal\Core\Field\FieldFilteredMarkup;
  8. /**
  9. * Implements hook_help().
  10. */
  11. function ouatt_admin_help($route_name, RouteMatchInterface $route_match) {
  12. switch ($route_name) {
  13. // Main module help for the editors_menus module.
  14. case 'help.page.ouatt_admin':
  15. $output = '';
  16. $output .= '<h3>' . t('About') . '</h3>';
  17. $output .= '<p>' . t('Où Atterrir admin twicks module') . '</p>';
  18. return $output;
  19. default:
  20. }
  21. }
  22. /**
  23. * Implements hook_form_FORM_ID_alter().
  24. */
  25. // function ouatt_admin_form_alter(&$form, $form_state, $form_id) {
  26. // }
  27. function ouatt_admin_form_node_concernement_edit_form_alter(&$form, $form_state, $form_id) {
  28. $concernement_node = $form_state->getFormObject()->getEntity();
  29. // concernement title
  30. $concernement_title = $concernement_node->getTitle();
  31. $form_state->setTemporaryValue("concernement_title", $concernement_title);
  32. // menace/maintien
  33. $field_entite_widget = $form['field_entite']['widget'];
  34. $i = 0;
  35. while (isset($field_entite_widget[$i]) && $item = $field_entite_widget[$i]) {
  36. $ief_id = $item['subform']['field_entite']['widget']['#ief_id'];
  37. $mm = $item['subform']['field_menace_maintien_degres']['widget'][0]['value']['#default_value'];
  38. $form_state->setTemporaryValue($ief_id . "_mm", $mm);
  39. $i++;
  40. }
  41. // actuel/future
  42. }
  43. /**
  44. * Perform alterations before an entity form is included in the IEF widget.
  45. *
  46. * @param array $entity_form
  47. * Nested array of form elements that comprise the entity form.
  48. * @param \Drupal\Core\Form\FormStateInterface $form_state
  49. * The form state of the parent form.
  50. */
  51. function ouatt_admin_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  52. // concernement title
  53. $concernement_title = $form_state->getTemporaryValue("concernement_title");
  54. // menace maintient
  55. $ief_id = $entity_form['#ief_id'];
  56. $mm = $form_state->getTemporaryValue($ief_id . "_mm");
  57. // field menace / maintient
  58. $mm_string = "menace / maintient";
  59. if ($mm > 0) {
  60. $mm_string = "maintient";
  61. } else if ($mm < 0) {
  62. $mm_string = "menace";
  63. }
  64. $entity_form['field_menace_maintien']['widget']['#description'] = FieldFilteredMarkup::create("Pouvez-vous décrire en quoi l'action $mm_string \"$concernement_title\" ?");
  65. $entity_form['field_menace_maintien']['widget'][0]['#description'] = FieldFilteredMarkup::create("Pouvez-vous décrire en quoi l'action $mm_string \"$concernement_title\" ?");
  66. $entity_form['field_menace_maintien']['widget'][0]['value']['#description'] = FieldFilteredMarkup::create("Pouvez-vous décrire en quoi l'action $mm_string \"$concernement_title\" ?");
  67. // field SOURCES
  68. // Comment avez-vous eu connaissance de cette menace / ce maintient ?
  69. $mm_string = "cette menace / ce maintient";
  70. if ($mm > 0) {
  71. $mm_string = "ce maintient";
  72. } else if ($mm < 0) {
  73. $mm_string = "cette menace";
  74. }
  75. $entity_form['field_sources']['widget']['#description'] = FieldFilteredMarkup::create("Comment avez-vous eu connaissance de $mm_string ?");
  76. }
  77. /**
  78. * Perform alterations before the reference form is included in the IEF widget.
  79. *
  80. * The reference form is used to add existing entities through an autocomplete
  81. * field.
  82. *
  83. * @param array $reference_form
  84. * Nested array of form elements that comprise the reference form.
  85. * @param \Drupal\Core\Form\FormStateInterface $form_state
  86. * The form state of the parent form.
  87. */
  88. // function ouatt_admin_inline_entity_form_reference_form_alter(&$reference_form, &$form_state) {
  89. // $t="t";
  90. // }
  91. /**
  92. * Alter the fields used to represent an entity in the IEF table.
  93. *
  94. * @param array $fields
  95. * The fields, keyed by field name.
  96. * @param array $context
  97. * An array with the following keys:
  98. * - parent_entity_type: The type of the parent entity.
  99. * - parent_bundle: The bundle of the parent entity.
  100. * - field_name: The name of the reference field on which IEF is operating.
  101. * - entity_type: The type of the referenced entities.
  102. * - allowed_bundles: Bundles allowed on the reference field.
  103. *
  104. * @see \Drupal\inline_entity_form\InlineFormInterface::getTableFields()
  105. */
  106. // function ouatt_admin_inline_entity_form_table_fields_alter($fields, $context) {
  107. // $t="t";
  108. // }
  109. /**
  110. * Provide post-processing of auto generated titles (labels).
  111. *
  112. * @param string $label
  113. * The auto-generated label to be altered.
  114. * @param object $entity
  115. * The entity that the label is from.
  116. *
  117. * @see \Drupal\auto_entitylabel\AutoEntityLabelManager::generateLabel()
  118. */
  119. function ouatt_admin_auto_entitylabel_label_alter(&$label, $entity) {
  120. if (strlen($label) > 50) {
  121. // if ($html) {
  122. // // Grabs the original and escapes any quotes
  123. // $original = str_replace('"', '\"', $label);
  124. // }
  125. // Truncates the string
  126. $label = substr(strip_tags($label), 0, 50);
  127. $label .= '...';
  128. }
  129. }