Commit 49b447a8 authored by peritus's avatar peritus Committed by Jakob P
Browse files

Issue #2997825 by david4lim, elaman, Akanksha92: Add Description label and...

Issue #2997825 by david4lim, elaman, Akanksha92: Add Description label and Description rows as settings
parent 821a578d
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ trait KeyValueWidgetTrait {
      'key_placeholder' => '',
      'value_label' => t('Value'),
      'description_enabled' => TRUE,
      'description_label' => t('Description'),
      'description_rows' => 5,
      'description_placeholder' => '',
    ] + parent::defaultSettings();
  }
@@ -77,6 +79,19 @@ trait KeyValueWidgetTrait {
      '#description' => t('Enable the description field (Generally used for administrative purposes).'),
      '#weight' => 2,
    ];
    // Add an element for the label of the value field.
    $element['description_label'] = [
      '#type' => 'textfield',
      '#title' => t('Description Label'),
      '#default_value' => $this->getSetting('description_label'),
      '#description' => t('Label for the "Description" field.'),
      '#weight' => 3,
      '#states' => [
        'visible' => [
          ':input[name="fields[' . $field_machine . '][settings_edit_form][settings][description_enabled]"]' => ['checked' => TRUE],
        ],
      ],
    ];
    // Add a placeholder for teh description field.
    $element['description_placeholder'] = [
      '#type' => 'textfield',
@@ -90,6 +105,18 @@ trait KeyValueWidgetTrait {
        ],
      ],
    ];
    $element['description_rows'] = [
      '#type' => 'number',
      '#title' => t('Description Rows'),
      '#default_value' => $this->getSetting('description_rows'),
      '#min' => 1,
      '#weight' => 5,
      '#states' => [
        'visible' => [
          ':input[name="fields[' . $field_machine . '][settings_edit_form][settings][description_enabled]"]' => ['checked' => TRUE],
        ],
      ],
    ];
    return $element + $parent_form;
  }

@@ -115,6 +142,8 @@ trait KeyValueWidgetTrait {
    if ($this->getSetting('description_enabled') && ($placeholder = $this->getSetting('description_placeholder')) && !empty($placeholder)) {
      $summary[] = t('Description: Enabled', ['@placeholder' => $placeholder]);
      $summary[] = t('- Placeholder: @placeholder', ['@placeholder' => $placeholder]);
      $summary[] = t('- Label: @label', ['@label' => $this->getSetting('description_label')]);
      $summary[] = t('- Rows: @rows', ['@rows' => $this->getSetting('description_rows')]);
    }

    return $summary + parent::settingsSummary();
@@ -146,6 +175,8 @@ trait KeyValueWidgetTrait {
    $value_label = $this->getSetting('value_label');
    $key_placeholder = $this->getSetting('key_placeholder');
    $description_enabled = $this->getSetting('description_enabled');
    $description_label = $this->getSetting('description_label');
    $description_rows = $this->getSetting('description_rows');
    $description_placeholder = $this->getSetting('description_placeholder');

    // Display the title for key_value fields.
@@ -156,11 +187,12 @@ trait KeyValueWidgetTrait {

    // Create a description field if it is enabled.
    $description = !$description_enabled ? [] : [
      '#title' => t('Description'),
      '#title' => $description_label,
      '#type' => 'textarea',
      '#default_value' => isset($items[$delta]->value) ? $items[$delta]->description : NULL,
      '#placeholder' => $description_placeholder,
      '#maxlength' => 255,
      '#rows' => $description_rows,
      '#weight' => 2,
      '#attributes' => [
        'class' => [