You are here

protected function FieldValidationRuleFormBase::findColumn in Field Validation 8

Handles switching the configuration type selector.

1 call to FieldValidationRuleFormBase::findColumn()
FieldValidationRuleFormBase::buildForm in src/Form/FieldValidationRuleFormBase.php

File

src/Form/FieldValidationRuleFormBase.php, line 203

Class

FieldValidationRuleFormBase
Provides a base form for FieldValidationRule.

Namespace

Drupal\field_validation\Form

Code

protected function findColumn($field_name) {

  //\Drupal::logger('field_validation')->notice('1234:' . $field_name);
  $column_options = [
    '' => $this
      ->t('- Select -'),
  ];
  if (empty($field_name)) {
    return $column_options;
  }
  $entity_type_id = $this->fieldValidationRuleSet
    ->getAttachedEntityType();
  $baseFieldDefinitions = \Drupal::service('entity_field.manager')
    ->getBaseFieldDefinitions($entity_type_id);
  $schema = [];
  if (isset($baseFieldDefinitions[$field_name])) {
    $field_info = $baseFieldDefinitions[$field_name];
    $schema = $field_info
      ->getSchema();
  }
  else {
    $field_info = \Drupal\field\Entity\FieldStorageConfig::loadByName($entity_type_id, $field_name);
    $schema = $field_info
      ->getSchema();
  }

  // \Drupal::logger('field_validation')->notice('1234:' . var_export($schema, true));
  if (!empty($schema['columns'])) {
    $columns = $schema['columns'];
    foreach ($columns as $key => $value) {
      $column_options[$key] = $key;
    }
  }
  return $column_options;
}