class TipPluginTextExtended in Tour UI 8
This plugin override Tour\tip\TipPluginText to add UI methods.
It should not appear as tour\tip plugin because tour_ui shouldn't be installed on production. So this plugin will not be availble anymore once the module will be installed. The only goal of this plugin is to provide missing ui methods for default tip text plugin.
Plugin annotation
@Tip(
id = "text_extended",
title = @Translation("Text")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\tour\TipPluginBase implements TipPluginInterface
- class \Drupal\tour\Plugin\tour\tip\TipPluginText implements ContainerFactoryPluginInterface
- class \Drupal\tour_ui\Plugin\tour_ui\tip\TipPluginTextExtended
- class \Drupal\tour\Plugin\tour\tip\TipPluginText implements ContainerFactoryPluginInterface
- class \Drupal\tour\TipPluginBase implements TipPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TipPluginTextExtended
File
- src/
Plugin/ tour_ui/ tip/ TipPluginTextExtended.php, line 23
Namespace
Drupal\tour_ui\Plugin\tour_ui\tipView source
class TipPluginTextExtended extends TipPluginText {
/**
* {@inheritdoc}
*
* TODO: Remove this method when
* https://www.drupal.org/node/2851166#comment-11925707 will be commited.
*/
public function getConfiguration() {
$names = [
'id',
'plugin',
'label',
'weight',
'attributes',
'body',
'location',
];
foreach ($names as $name) {
$properties[$name] = $this
->get($name);
}
return $properties;
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* Validates the selector_type tip optionsForm().
*
* @param mixed $element
* The form element that has the validate attached.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The state of the form after submission.
* @param array $form
* The form array.
*/
public function optionsFormValidate($element, FormStateInterface $form_state, array $form) {
$selector_type = $form_state
->get([
'attributes',
'selector_type',
]);
$form_state
->unsetValue([
'attributes',
'selector_type',
]);
// If selector_type is modal we need to ensure that there is
// no data-id or data-class specified.
if ($selector_type == 'modal') {
$form_state
->unsetValue([
'attributes',
'data-id',
]);
$form_state
->unsetValue([
'attributes',
'data-class',
]);
}
// If data-id was selected and no id provided.
if ($selector_type == 'data-id' && $form_state
->isValueEmpty([
'attributes',
'data-id',
])) {
$form_state
->setError($form['attributes']['data-id'], $this
->t('Please provide a data id.'));
}
// If data-class was selected and no class provided.
if ($selector_type == 'data-class' && $form_state
->isValueEmpty([
'attributes',
'data-class',
])) {
$form_state
->setError($form['attributes']['data-class'], $this
->t('Please provide a data class.'));
}
// Remove the data-class value if data-id is provided.
if ($selector_type == 'data-id') {
$form_state
->unsetValue([
'attributes',
'data-class',
]);
}
// Remove the data-id value is data-class is provided.
if ($selector_type == 'data-class') {
$form_state
->unsetValue([
'attributes',
'data-id',
]);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TipPluginBase:: |
protected | property | The attributes that will be applied to the markup of this tip. | |
TipPluginBase:: |
protected | property | The label which is used for render of this tip. | |
TipPluginBase:: |
protected | property | Allows tips to take more priority that others. | |
TipPluginBase:: |
public | function |
Used for returning values by key. Overrides TipPluginInterface:: |
|
TipPluginBase:: |
public | function |
Returns label of the tip. Overrides TipPluginInterface:: |
|
TipPluginBase:: |
public | function |
Returns weight of the tip. Overrides TipPluginInterface:: |
|
TipPluginBase:: |
public | function |
Returns id of the tip. Overrides TipPluginInterface:: |
|
TipPluginBase:: |
public | function |
Used for returning values by key. Overrides TipPluginInterface:: |
|
TipPluginText:: |
protected | property | Unique aria-id. | |
TipPluginText:: |
protected | property | The body text which is used for render of this Text Tip. | |
TipPluginText:: |
protected | property | The forced position of where the tip will be located. | |
TipPluginText:: |
protected | property | Token service. | |
TipPluginText:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
TipPluginText:: |
public | function | Returns a ID that is guaranteed uniqueness. | |
TipPluginText:: |
public | function |
Returns an array of attributes for the tip wrapper. Overrides TipPluginBase:: |
|
TipPluginText:: |
public | function | Returns body of the text tip. | |
TipPluginText:: |
public | function | Returns location of the text tip. | |
TipPluginText:: |
public | function |
Returns a renderable array. Overrides TipPluginInterface:: |
|
TipPluginText:: |
public | function |
Constructs a \Drupal\tour\Plugin\tour\tip\TipPluginText object. Overrides PluginBase:: |
|
TipPluginTextExtended:: |
public | function | ||
TipPluginTextExtended:: |
public | function | TODO: Remove this method when https://www.drupal.org/node/2851166#comment-11925707 will be commited. | |
TipPluginTextExtended:: |
public | function | Validates the selector_type tip optionsForm(). | |
TipPluginTextExtended:: |
public | function |