protected function TransactorBase::setFieldDisplay in Transaction 8
Enable the display of a field.
Parameters
string $field_name: The field name.
array $field_info: The field info array as defined in the transactor plugin.
string $bundle: The bundle.
string $type: (optional) The display type, view or form.
string $mode: (optional) The view mode.
array $options: (optional) Display options.
Return value
null|\Drupal\Core\Entity\Display\EntityDisplayInterface The display config object. NULL on unrecognized display type or mode.
1 call to TransactorBase::setFieldDisplay()
- TransactorBase::submitConfigurationForm in src/
TransactorBase.php - Handles the settings form submit for this transactor plugin.
File
- src/
TransactorBase.php, line 633
Class
- TransactorBase
- Provides a base class for transactor plugins.
Namespace
Drupal\transactionCode
protected function setFieldDisplay($field_name, array $field_info, $bundle, $type = 'view', $mode = 'default', array $options = []) {
$display_id = $field_info['entity_type'] . '.' . $bundle . '.' . $mode;
$display_values = [
'targetEntityType' => $field_info['entity_type'],
'bundle' => $bundle,
'mode' => $mode,
'status' => TRUE,
];
if (!isset($options['weight'])) {
$options['weight'] = 0;
}
switch ($type) {
case 'form':
if (!($display = EntityFormDisplay::load($display_id))) {
$display = EntityFormDisplay::create($display_values);
}
$display
->setComponent($field_name, $options);
$display
->save();
break;
case 'view':
if (!($display = EntityViewDisplay::load($display_id))) {
$display = EntityViewDisplay::create($display_values);
}
$display
->setComponent($field_name, $options);
$display
->save();
break;
default:
$display = NULL;
}
return $display;
}