You are here

public function UIOverrideProvider::referenceFormFieldsOverride in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/UIOverrideProvider.php \Drupal\bibcite_entity\UIOverrideProvider::referenceFormFieldsOverride()

Override elements attributes based on bundle configuration.

Parameters

array $element: Element render array.

string $bundle_id: Entity bundle identifier.

File

modules/bibcite_entity/src/UIOverrideProvider.php, line 55

Class

UIOverrideProvider
Collection of hardcoded overrides for reference form and view.

Namespace

Drupal\bibcite_entity

Code

public function referenceFormFieldsOverride(array &$element, $bundle_id) {

  /** @var \Drupal\bibcite_entity\Entity\ReferenceTypeInterface $bundle */
  if (($bundle = $this->typeStorage
    ->load($bundle_id)) && $bundle
    ->isRequiredOverride()) {
    foreach ($bundle
      ->getFields() as $field_name => $field_config) {
      if (isset($element[$field_name])) {
        if (!empty($field_config['label'])) {
          $this
            ->setFormElementParameter($element[$field_name], '#title', $field_config['label']);
        }
        if (!empty($field_config['hint'])) {
          $this
            ->setFormElementParameter($element[$field_name], '#description', $field_config['hint']);
        }
        if ($field_config['required']) {
          $this
            ->setFormElementParameter($element[$field_name], '#required', $field_config['required']);
        }
      }
    }
  }
}