You are here

public function TipPluginTextExtended::buildConfigurationForm in Tour UI 8

File

src/Plugin/tour_ui/tip/TipPluginTextExtended.php, line 50

Class

TipPluginTextExtended
This plugin override Tour\tip\TipPluginText to add UI methods.

Namespace

Drupal\tour_ui\Plugin\tour_ui\tip

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $id = $this
    ->get('id');
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#required' => TRUE,
    '#default_value' => $this
      ->get('label'),
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#machine_name' => [
      'exists' => '\\Drupal\\tour\\Entity\\Tour::load',
      'replace_pattern' => '[^a-z0-9-]+',
      'replace' => '-',
    ],
    '#default_value' => $id,
    '#disabled' => !empty($id),
  ];
  $form['plugin'] = [
    '#type' => 'value',
    '#value' => $this
      ->get('plugin'),
  ];
  $form['weight'] = [
    '#type' => 'weight',
    '#title' => $this
      ->t('Weight'),
    '#default_value' => $this
      ->get('weight'),
    '#attributes' => [
      'class' => [
        'tip-order-weight',
      ],
    ],
    '#delta' => 100,
  ];
  $attributes = $this
    ->getAttributes();
  $form['attributes'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Attributes'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  ];

  // Determine the type identifier of the tip.
  if (!empty($attributes['data-id'])) {
    $tip_type = 'data-id';
  }
  elseif (!empty($attributes['data-class'])) {
    $tip_type = 'data-class';
  }
  else {
    $tip_type = 'modal';
  }
  $form['attributes']['selector_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Selector type'),
    '#description' => $this
      ->t('The type of selector that this tip will target.'),
    '#options' => [
      'data-id' => $this
        ->t('Data ID'),
      'data-class' => $this
        ->t('Data Class'),
      'modal' => $this
        ->t('Modal'),
    ],
    '#default_value' => $tip_type,
    '#element_validate' => [
      [
        $this,
        'optionsFormValidate',
      ],
    ],
  ];
  $form['attributes']['data-id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Data id'),
    '#description' => $this
      ->t('Provide the ID of the page element.'),
    '#field_prefix' => '#',
    '#default_value' => !empty($attributes['data-id']) ? $attributes['data-id'] : '',
    '#states' => [
      'visible' => [
        'select[name="attributes[selector_type]"]' => [
          'value' => 'data-id',
        ],
      ],
      'enabled' => [
        'select[name="attributes[selector_type]"]' => [
          'value' => 'data-id',
        ],
      ],
    ],
  ];
  $form['attributes']['data-class'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Data class'),
    '#description' => $this
      ->t('Provide the Class of the page element. You can provide more complex jquery selection like <pre>action-links a[href="/admin/structure/forum/add/forum"]</pre>'),
    '#field_prefix' => '.',
    '#default_value' => !empty($attributes['data-class']) ? $attributes['data-class'] : '',
    '#states' => [
      'visible' => [
        'select[name="attributes[selector_type]"]' => [
          'value' => 'data-class',
        ],
      ],
      'enabled' => [
        'select[name="attributes[selector_type]"]' => [
          'value' => 'data-class',
        ],
      ],
    ],
  ];
  $form['location'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Location'),
    '#options' => [
      'top' => $this
        ->t('Top'),
      'bottom' => $this
        ->t('Bottom'),
      'left' => $this
        ->t('Left'),
      'right' => $this
        ->t('Right'),
    ],
    '#default_value' => $this
      ->get('location'),
  ];
  $tags = Xss::getAdminTagList();
  $form['body'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Body'),
    '#required' => TRUE,
    '#default_value' => $this
      ->get('body'),
    '#description' => $this
      ->t('You could use the following tags: %s', [
      '%s' => implode(', ', $tags),
    ]),
  ];
  return $form;
}