protected function EntityDisplaySettingsBulkCopyForm::getDisplayOptions in Field tools 8
Get the form options for a display type.
@todo refactor to a trait.
Parameters
$type: The entity type ID of the display type.
$entity_type_id: The target entity type ID of the displays.
$bundle: The target bundle.
Return value
An array of form options.
1 call to EntityDisplaySettingsBulkCopyForm::getDisplayOptions()
- EntityDisplaySettingsBulkCopyForm::buildForm in src/
Form/ EntityDisplaySettingsBulkCopyForm.php - Form constructor.
File
- src/
Form/ EntityDisplaySettingsBulkCopyForm.php, line 208
Class
- EntityDisplaySettingsBulkCopyForm
- Provides a form to copy displays settings between displays.
Namespace
Drupal\field_tools\FormCode
protected function getDisplayOptions($type, $entity_type_id, $bundle) {
$display_options = [];
$types = [
'entity_form_display' => 'Form',
'entity_view_display' => 'View',
];
foreach ($types as $type => $label) {
$display_ids = $this->entityTypeManager
->getStorage($type)
->getQuery()
->condition('targetEntityType', $entity_type_id)
->condition('bundle', $bundle)
->execute();
$displays = $this->entityTypeManager
->getStorage($type)
->loadMultiple($display_ids);
// Unfortunately, getDisplayModesByEntityType() is protected :(
if ($type == 'entity_form_display') {
$mode_options = $this->entityDisplayRepository
->getFormModeOptions($entity_type_id);
}
else {
$mode_options = $this->entityDisplayRepository
->getViewModeOptions($entity_type_id);
}
foreach ($displays as $id => $display) {
// The label() method of displays returns NULL always, so we get the label
// from the related mode.
$display_options[$type . ':' . $id] = $label . ': ' . $mode_options[$display
->getMode()];
}
// Sort within each type.
asort($display_options);
}
return $display_options;
}