protected function ImagePopupFieldFormatter::getFieldOptions in Simple Image Popup 2.x
Find fields on the entity that are valid alt or title text.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
array The valid fields as $id => $title.
1 call to ImagePopupFieldFormatter::getFieldOptions()
- ImagePopupFieldFormatter::getAdditionalImageFields in src/
Plugin/ Field/ FieldFormatter/ ImagePopupFieldFormatter.php - Creates alt and title fields for a base image context field.
File
- src/
Plugin/ Field/ FieldFormatter/ ImagePopupFieldFormatter.php, line 347
Class
- ImagePopupFieldFormatter
- Plugin implementation of the 'image_popup_field_formatter' formatter.
Namespace
Drupal\image_popup\Plugin\Field\FieldFormatterCode
protected function getFieldOptions(FormStateInterface $form_state) {
// The result is kept in $this->fieldOptions so that it only needs to be
// processed once per instantiation of this class.
if (!isset($this->fieldOptions)) {
$this->fieldOptions = [];
// Discover the entity type and bundle this field is being created for.
$entity = $form_state
->getBuildInfo()['callback_object']
->getEntity();
$entity_type = $entity
->getTargetEntityTypeId();
$bundle = $entity
->getTargetBundle();
// Get all the string fields.
$field_map = $this->entityFieldManager
->getFieldMapByFieldType('string');
// Find fields from the map that are on this entity type and bundle.
if (isset($field_map[$entity_type])) {
$field_ids = array_keys($field_map[$entity_type]);
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($entity_type, $bundle);
// Provide the entity's string fields as options.
foreach ($field_ids as $field_id) {
if (!empty($field_definitions[$field_id])) {
$this->fieldOptions[$field_id] = $field_definitions[$field_id]
->getLabel();
}
}
}
}
return $this->fieldOptions;
}