public function BlazyAdminFormatterBase::getFieldOptions in Blazy 7
Same name and namespace in other branches
- 8.2 src/Form/BlazyAdminFormatterBase.php \Drupal\blazy\Form\BlazyAdminFormatterBase::getFieldOptions()
- 8 src/Form/BlazyAdminFormatterBase.php \Drupal\blazy\Form\BlazyAdminFormatterBase::getFieldOptions()
Returns available fields for select options.
File
- src/
Form/ BlazyAdminFormatterBase.php, line 187
Class
- BlazyAdminFormatterBase
- A base for field formatter admin to have re-usable methods in one place.
Namespace
Drupal\blazy\FormCode
public function getFieldOptions($instance, $field_types, $target_type = 'file', array $bundles = []) {
$options = [];
$allowed_bundles = array_filter($this
->getBundles($instance, $bundles));
// Add panelizer support.
if ($instance['entity_type'] == 'ctools') {
$bundles = array_filter($bundles);
foreach ($bundles as $bundle_type => $types) {
foreach ($types as $type) {
$instance = field_info_instance($bundle_type, $instance['field_name'], $type);
$allowed_bundles = $this
->getBundles($instance, $bundles);
$options += $this
->getFieldOptionsInternal($allowed_bundles, $target_type, $field_types);
}
}
}
else {
$options = $this
->getFieldOptionsInternal($allowed_bundles, $target_type, $field_types);
}
if (empty($options)) {
$fields = field_info_fields();
$bundle_instance = $instance['field_name'];
foreach ($fields as $name => $field) {
$infos = field_info_instance($target_type, $name, $bundle_instance);
if (empty($field_types) && isset($infos['label'])) {
$options[$name] = $infos['label'];
}
else {
if (in_array($target_type, array_keys($field['bundles'])) && in_array($bundle_instance, $field['bundles'][$target_type]) && in_array($field['type'], $field_types)) {
$options[$name] = $infos['label'];
}
}
}
}
return $options;
}