function ds_extras_form_entity_view_display_edit_form_alter in Display Suite 8.2
Same name and namespace in other branches
- 8.3 modules/ds_extras/ds_extras.module \ds_extras_form_entity_view_display_edit_form_alter()
Implements hook_form_FORM_ID_alter().
File
- modules/
ds_extras/ ds_extras.module, line 54 - Display Suite extras main functions.
Code
function ds_extras_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) {
// Region to block only fires if there is a layout and we're working on the
// a view mode which is not equal to default.
$mode = $form_state
->getFormObject()
->getEntity()
->getMode();
if (isset($form['#ds_layout']) && $mode != 'default' && \Drupal::config('ds_extras.settings')
->get('region_to_block')) {
// Get the entity_type, bundle and view mode.
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
$view_mode = $mode;
$region_blocks_options = array();
$region_blocks = \Drupal::config('ds_extras.settings')
->get('region_blocks');
if (!empty($region_blocks)) {
foreach ($region_blocks as $key => $block) {
if ($block['info'] == "{$entity_type}_{$bundle}_{$view_mode}") {
$region_blocks_options[$key] = t('Remove') . ' ' . $block['title'];
}
}
}
$form['region_to_block'] = array(
'#type' => 'details',
'#group' => 'additional_settings',
'#title' => t('Block regions (deprecated)'),
'#description' => t('Create additional regions in this layout which will be exposed as blocks.'),
);
$url = Url::fromUri('https://www.drupal.org/node/2754967');
$link = Drupal::l(t('handbook page'), $url);
$form['region_to_block']['deprecated'] = array(
'#markup' => '<b>' . t('This functionality is not compatible with some caching modules. Read the @handbook for a better alternative.', array(
'@handbook' => $link,
)) . '</b>',
);
$form['region_to_block']['new_block_region'] = array(
'#type' => 'textfield',
'#title' => t('Region name'),
'#description' => t('Enter a name to create a new region.'),
);
$form['region_to_block']['new_block_region_key'] = array(
'#title' => t('Machine name'),
'#type' => 'machine_name',
'#default_value' => '',
'#maxlength' => 32,
'#required' => FALSE,
'#description' => t('The machine-readable name of this block region. This name must contain only lowercase letters and underscores. This name must be unique.'),
'#disabled' => FALSE,
'#machine_name' => array(
'exists' => 'ds_extras_region_to_block_unique',
'source' => array(
'region_to_block',
'new_block_region',
),
),
);
if (!empty($region_blocks_options)) {
$form['region_to_block']['remove_block_region'] = array(
'#type' => 'checkboxes',
'#title' => t('Existing block regions'),
'#options' => $region_blocks_options,
'#description' => t('Check the regions you want to remove.'),
);
}
$form['actions']['submit']['#submit'][] = 'ds_extras_block_submit';
}
}