public function ViewModeSelectorWidgetBase::__construct in Opigno certificate 3.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldWidget/ViewModeSelectorWidgetBase.php \Drupal\opigno_certificate\Plugin\Field\FieldWidget\ViewModeSelectorWidgetBase::__construct()
ViewModeSelectorWidgetBase constructor.
Parameters
string $plugin_id:
mixed $plugin_definition:
\Drupal\Core\Field\FieldDefinitionInterface $field_definition:
array $settings:
array $third_party_settings:
\Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository:
Overrides WidgetBase::__construct
1 call to ViewModeSelectorWidgetBase::__construct()
- ViewModeSelectorSelect::__construct in src/
Plugin/ Field/ FieldWidget/ ViewModeSelectorSelect.php - Gather all available view modes.
1 method overrides ViewModeSelectorWidgetBase::__construct()
- ViewModeSelectorSelect::__construct in src/
Plugin/ Field/ FieldWidget/ ViewModeSelectorSelect.php - Gather all available view modes.
File
- src/
Plugin/ Field/ FieldWidget/ ViewModeSelectorWidgetBase.php, line 38
Class
- ViewModeSelectorWidgetBase
- Base class for the 'view_mode_selector_*' widgets.
Namespace
Drupal\opigno_certificate\Plugin\Field\FieldWidgetCode
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityDisplayRepositoryInterface $entity_display_repository) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$this->entityDisplayRepository = $entity_display_repository;
$field_settings = $field_definition
->getSettings();
$entity_type = $field_definition
->getTargetEntityTypeId();
$bundle = $field_definition
->getTargetBundle();
// Get all view modes for the current bundle.
$view_modes = $this->entityDisplayRepository
->getViewModeOptionsByBundle($entity_type, $bundle);
// Reduce options by enabled view modes
foreach (array_keys($view_modes) as $view_mode) {
if (isset($field_settings['view_modes'][$view_mode]['enable']) && $field_settings['view_modes'][$view_mode]['enable']) {
continue;
}
unset($view_modes[$view_mode]);
}
// Show all view modes in widget when no view modes are enabled.
if (!count($view_modes)) {
$view_modes = $this->entityDisplayRepository
->getViewModeOptionsByBundle($entity_type, $bundle);
}
$this->viewModes = $view_modes;
}