123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- /**
- * @file
- * Contains admin_menus.module.
- */
- use Drupal\Core\Routing\RouteMatchInterface;
- use Drupal\Core\Field\FieldFilteredMarkup;
- /**
- * Implements hook_help().
- */
- function ouatt_admin_help($route_name, RouteMatchInterface $route_match) {
- switch ($route_name) {
- // Main module help for the editors_menus module.
- case 'help.page.ouatt_admin':
- $output = '';
- $output .= '<h3>' . t('About') . '</h3>';
- $output .= '<p>' . t('Où Atterrir admin twicks module') . '</p>';
- return $output;
- default:
- }
- }
- /**
- * Implements hook_form_FORM_ID_alter().
- */
- // function ouatt_admin_form_alter(&$form, $form_state, $form_id) {
-
- // }
- function ouatt_admin_form_node_concernement_edit_form_alter(&$form, $form_state, $form_id) {
- $concernement_node = $form_state->getFormObject()->getEntity();
- // concernement title
- $concernement_title = $concernement_node->getTitle();
- $form_state->setTemporaryValue("concernement_title", $concernement_title);
- // menace/maintien
- $field_entite_widget = $form['field_entite']['widget'];
- $i = 0;
- while (isset($field_entite_widget[$i]) && $item = $field_entite_widget[$i]) {
- $ief_id = $item['subform']['field_entite']['widget']['#ief_id'];
- $mm = $item['subform']['field_menace_maintien_degres']['widget'][0]['value']['#default_value'];
- $form_state->setTemporaryValue($ief_id . "_mm", $mm);
- $i++;
- }
- // actuel/future
- }
- /**
- * Perform alterations before an entity form is included in the IEF widget.
- *
- * @param array $entity_form
- * Nested array of form elements that comprise the entity form.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The form state of the parent form.
- */
- function ouatt_admin_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
- // concernement title
- $concernement_title = $form_state->getTemporaryValue("concernement_title");
-
- // menace maintient
- $ief_id = $entity_form['#ief_id'];
- $mm = $form_state->getTemporaryValue($ief_id . "_mm");
- // field menace / maintient
- $mm_string = "menace / maintient";
- if ($mm > 0) {
- $mm_string = "maintient";
- } else if ($mm < 0) {
- $mm_string = "menace";
- }
- $entity_form['field_menace_maintien']['widget']['#description'] = FieldFilteredMarkup::create("Pouvez-vous décrire en quoi l'action $mm_string \"$concernement_title\" ?");
- $entity_form['field_menace_maintien']['widget'][0]['#description'] = FieldFilteredMarkup::create("Pouvez-vous décrire en quoi l'action $mm_string \"$concernement_title\" ?");
- $entity_form['field_menace_maintien']['widget'][0]['value']['#description'] = FieldFilteredMarkup::create("Pouvez-vous décrire en quoi l'action $mm_string \"$concernement_title\" ?");
-
- // field SOURCES
- // Comment avez-vous eu connaissance de cette menace / ce maintient ?
- $mm_string = "cette menace / ce maintient";
- if ($mm > 0) {
- $mm_string = "ce maintient";
- } else if ($mm < 0) {
- $mm_string = "cette menace";
- }
- $entity_form['field_sources']['widget']['#description'] = FieldFilteredMarkup::create("Comment avez-vous eu connaissance de $mm_string ?");
- }
- /**
- * Perform alterations before the reference form is included in the IEF widget.
- *
- * The reference form is used to add existing entities through an autocomplete
- * field.
- *
- * @param array $reference_form
- * Nested array of form elements that comprise the reference form.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The form state of the parent form.
- */
- // function ouatt_admin_inline_entity_form_reference_form_alter(&$reference_form, &$form_state) {
- // $t="t";
- // }
- /**
- * Alter the fields used to represent an entity in the IEF table.
- *
- * @param array $fields
- * The fields, keyed by field name.
- * @param array $context
- * An array with the following keys:
- * - parent_entity_type: The type of the parent entity.
- * - parent_bundle: The bundle of the parent entity.
- * - field_name: The name of the reference field on which IEF is operating.
- * - entity_type: The type of the referenced entities.
- * - allowed_bundles: Bundles allowed on the reference field.
- *
- * @see \Drupal\inline_entity_form\InlineFormInterface::getTableFields()
- */
- // function ouatt_admin_inline_entity_form_table_fields_alter($fields, $context) {
- // $t="t";
- // }
- /**
- * Provide post-processing of auto generated titles (labels).
- *
- * @param string $label
- * The auto-generated label to be altered.
- * @param object $entity
- * The entity that the label is from.
- *
- * @see \Drupal\auto_entitylabel\AutoEntityLabelManager::generateLabel()
- */
- function ouatt_admin_auto_entitylabel_label_alter(&$label, $entity) {
- if (strlen($label) > 50) {
- // if ($html) {
- // // Grabs the original and escapes any quotes
- // $original = str_replace('"', '\"', $label);
- // }
- // Truncates the string
- $label = substr(strip_tags($label), 0, 50);
- $label .= '...';
- }
- }
|