public static function ParagraphsFeatures::getThirdPartyForm in Paragraphs Features 2.x
Same name and namespace in other branches
- 8 src/ParagraphsFeatures.php \Drupal\paragraphs_features\ParagraphsFeatures::getThirdPartyForm()
Get 3rd party setting form for paragraphs features.
Parameters
\Drupal\Core\Field\WidgetInterface $plugin: Widget plugin.
string $field_name: Field name.
Return value
array Returns 3rd party form elements.
1 call to ParagraphsFeatures::getThirdPartyForm()
File
- src/
ParagraphsFeatures.php, line 118
Class
- ParagraphsFeatures
- Paragraphs features class.
Namespace
Drupal\paragraphs_featuresCode
public static function getThirdPartyForm(WidgetInterface $plugin, $field_name) {
$elements = [];
$disabled = FALSE;
if (!in_array(\Drupal::theme()
->getActiveTheme()
->getName(), [
'claro',
'gin',
])) {
$disabled = TRUE;
}
$elements['delete_confirmation'] = [
'#type' => 'checkbox',
'#title' => t('Enable confirmation on paragraphs remove'),
'#default_value' => $plugin
->getThirdPartySetting('paragraphs_features', 'delete_confirmation'),
'#attributes' => [
'class' => [
'paragraphs-features__delete-confirmation__option',
],
],
];
// Define rule for enabling/disabling options that depend on modal add mode.
$modal_related_options_rule = [
':input[name="fields[' . $field_name . '][settings_edit_form][settings][add_mode]"]' => [
'value' => 'modal',
],
];
$elements['add_in_between'] = [
'#type' => 'checkbox',
'#title' => t('Enable add in between buttons'),
'#default_value' => $plugin
->getThirdPartySetting('paragraphs_features', 'add_in_between'),
'#attributes' => [
'class' => [
'paragraphs-features__add-in-between__option',
],
],
'#states' => [
'enabled' => $modal_related_options_rule,
'visible' => $modal_related_options_rule,
],
];
$elements['sorting'] = [
'#type' => 'checkbox',
'#title' => t('Enable checkbox sorting'),
'#default_value' => $plugin
->getThirdPartySetting('paragraphs_features', 'sorting'),
'#attributes' => [
'class' => [
'paragraphs-features__sorting__option',
],
],
'#states' => [
'enabled' => !$modal_related_options_rule && !$disabled,
'visible' => $modal_related_options_rule,
],
'#disabled' => $disabled,
'#description' => $disabled ? t('This feature only works with claro / gin themes.') : '',
];
$elements['split_text'] = [
'#type' => 'checkbox',
'#title' => t('Enable split text for text paragraphs'),
'#default_value' => $plugin
->getThirdPartySetting('paragraphs_features', 'split_text'),
'#attributes' => [
'class' => [
'paragraphs-features__split-text__option',
],
],
'#states' => [
'enabled' => $modal_related_options_rule,
'visible' => $modal_related_options_rule,
],
];
// Only show the drag & drop feature if we can find the sortable library.
$library_discovery = \Drupal::service('library.discovery');
$library = $library_discovery
->getLibraryByName('paragraphs', 'paragraphs-dragdrop');
$elements['show_drag_and_drop'] = [
'#type' => 'checkbox',
'#title' => t('Show drag & drop button'),
'#default_value' => $plugin
->getThirdPartySetting('paragraphs_features', 'show_drag_and_drop', TRUE),
'#access' => !empty($library),
];
return $elements;
}