You are here

public function EntityInlineForm::getTableFields in Inline Entity Form 8

Gets the columns used to represent an entity in the IEF table.

Modules can alter the output of this method through hook_inline_entity_form_table_fields_alter().

Parameters

string[] $bundles: An array of allowed bundles for this widget.

Return value

array An array of data about table columns keyed by column name. Each column is represented by an associative array containing the following keys:

  • type: One of 'label', 'field' or 'callback', which indicates how this column should be handled:

    • 'label': The entity's label.
    • 'field': A field value from the entity. The name of the field is given by the key in this array.
    • 'callback': A callback, given by the 'callback' property.

    @see template_preprocess_inline_entity_form_entity_table() for the handling of these.

  • label: the title of the table field's column in the IEF table.
  • weight: the sort order of the column in the IEF table.
  • display_options: (optional) used for 'field' type table columns, an array of display settings. See EntityViewBuilderInterface::viewField().
  • callback: for 'callback' type table columns, a callable that returns a renderable array.
  • callback_arguments: (optional) an array of additional arguments to pass to the callback. The entity and the theme variables are always passed as as the first two arguments.

Overrides InlineFormInterface::getTableFields

1 call to EntityInlineForm::getTableFields()
NodeInlineForm::getTableFields in src/Form/NodeInlineForm.php
Gets the columns used to represent an entity in the IEF table.
1 method overrides EntityInlineForm::getTableFields()
NodeInlineForm::getTableFields in src/Form/NodeInlineForm.php
Gets the columns used to represent an entity in the IEF table.

File

src/Form/EntityInlineForm.php, line 115

Class

EntityInlineForm
Generic entity inline form handler.

Namespace

Drupal\inline_entity_form\Form

Code

public function getTableFields($bundles) {
  $definitions = $this->entityFieldManager
    ->getBaseFieldDefinitions($this->entityType
    ->id());
  $label_key = $this->entityType
    ->getKey('label');
  $label_field_label = $this
    ->t('Label');
  if ($label_key && isset($definitions[$label_key])) {
    $label_field_label = $definitions[$label_key]
      ->getLabel();
  }
  $bundle_key = $this->entityType
    ->getKey('bundle');
  $bundle_field_label = $this
    ->t('Type');
  if ($bundle_key && isset($definitions[$bundle_key])) {
    $bundle_field_label = $definitions[$bundle_key]
      ->getLabel();
  }
  $fields = [];
  $fields['label'] = [
    'type' => 'label',
    'label' => $label_field_label,
    'weight' => 1,
  ];
  if (count($bundles) > 1) {
    $fields[$bundle_key] = [
      'type' => 'field',
      'label' => $bundle_field_label,
      'weight' => 2,
      'display_options' => [
        'type' => 'entity_reference_label',
        'settings' => [
          'link' => FALSE,
        ],
      ],
    ];
  }
  return $fields;
}