function _ief_table_view_mode_add_extra_field in Inline Entity Form Table View Mode 8.2
Same name and namespace in other branches
- 8 ief_table_view_mode.module \_ief_table_view_mode_add_extra_field()
- 7 ief_table_view_mode.module \_ief_table_view_mode_add_extra_field()
Add a new extra field in the table of the UI.
Parameters
array $element: The element with all fields.
string $field_id: The machine name of the extra field.
array $extra_field: The definition of the field from ief.
array $display: The view setting of the field.
\Drupal\Core\Entity\EntityInterface $entity: The entity display.
\Drupal\field_ui\Form\EntityDisplayFormBase $formObject: The form object display form.
1 call to _ief_table_view_mode_add_extra_field()
- ief_table_view_mode_form_entity_view_display_edit_form_alter in ./
ief_table_view_mode.module - Implements hook_form_FORM_ID_alter() for entity_view_display_edit_form() form.
File
- ./
ief_table_view_mode.module, line 184 - Defines a view mode to set up the columns of the table for the IEF widget.
Code
function _ief_table_view_mode_add_extra_field(array &$element, $field_id, array $extra_field, array $display, EntityInterface $entity, EntityDisplayFormBase $formObject) {
$string_translation = \Drupal::translation();
$display_options = $entity
->getComponent($field_id);
$regions = array_keys($formObject
->getRegions());
$regions_options = $formObject
->getRegionOptions();
$label = is_string($extra_field['label']) ? $extra_field['label'] : $extra_field['label']
->render();
$element[$field_id] = [
'#attributes' => [
'class' => [
'draggable',
'tabledrag-leaf',
],
],
'#row_type' => 'extra_field',
'#region_callback' => [
$formObject,
'getRowRegion',
],
'#js_settings' => [
'rowHandler' => 'field',
],
'human_name' => [
'#markup' => $label . '*',
],
'weight' => [
'#type' => 'textfield',
'#title' => $string_translation
->translate('Weight for @title', [
'@title' => $label,
]),
'#title_display' => 'invisible',
'#default_value' => $display_options ? $display_options['weight'] : 0,
'#size' => 3,
'#attributes' => [
'class' => [
'field-weight',
],
],
],
'parent_wrapper' => [
'parent' => [
'#type' => 'select',
'#title' => $string_translation
->translate('Parents for @title', [
'@title' => $label,
]),
'#title_display' => 'invisible',
'#options' => array_combine($regions, $regions),
'#empty_value' => '',
'#attributes' => [
'class' => [
'js-field-parent',
'field-parent',
],
],
'#parents' => [
'fields',
$field_id,
'parent',
],
],
'hidden_name' => [
'#type' => 'hidden',
'#default_value' => $field_id,
'#attributes' => [
'class' => [
'field-name',
],
],
],
],
'region' => [
'#type' => 'select',
'#title' => $string_translation
->translate('Region for @title', [
'@title' => $label,
]),
'#title_display' => 'invisible',
'#options' => $regions_options,
'#default_value' => $display_options ? $display_options['region'] : 'hidden',
'#attributes' => [
'class' => [
'field-region',
],
],
],
'plugin' => [
'type' => [
'#type' => 'hidden',
'#value' => $display_options ? 'visible' : 'hidden',
'#parents' => [
'fields',
$field_id,
'type',
],
'#attributes' => [
'class' => [
'field-plugin-type',
],
],
],
],
'settings_summary' => [],
'settings_edit' => [],
];
}