function paragraph_view_mode_form_paragraphs_type_edit_form_alter in Paragraph View Mode 2.x
Same name and namespace in other branches
- 8 paragraph_view_mode.module \paragraph_view_mode_form_paragraphs_type_edit_form_alter()
Implements hook_form_FORM_ID_alter().
File
- ./
paragraph_view_mode.module, line 56 - Contains paragraphs_view_mode.module functions.
Code
function paragraph_view_mode_form_paragraphs_type_edit_form_alter(&$form, FormStateInterface $form_state) {
$paragraph = $form_state
->getFormObject();
$paragraphType = $paragraph
->getEntity();
$config_name = StorageManagerInterface::CONFIG_NAME;
$form[$config_name] = [
'#title' => t(StorageManagerInterface::FIELD_LABEL),
'#type' => 'details',
'#tree' => TRUE,
'#open' => TRUE,
];
$form[$config_name]['enabled'] = [
'#title' => t('Enable @label field on this @type type.', [
'@label' => StorageManagerInterface::FIELD_LABEL,
'@type' => StorageManagerInterface::ENTITY_TYPE,
]),
'#type' => 'checkbox',
'#default_value' => $paragraphType
->getThirdPartySetting($config_name, 'enabled') ?: FALSE,
];
$form[$config_name]['label'] = [
'#title' => t('Label'),
"#description" => t('If you do not set the label, the default will be used instead: %label', [
'%label' => StorageManagerInterface::FIELD_LABEL,
]),
'#type' => 'textfield',
'#default_value' => $paragraphType
->getThirdPartySetting($config_name, 'label') ?: NULL,
'#states' => [
'visible' => [
':input[name="paragraph_view_mode[enabled]"]' => [
'checked' => TRUE,
],
],
],
];
$form['actions']['submit']['#submit'][] = 'paragraph_view_mode_form_paragraphs_type_edit_form_submit';
}