You are here

public function BulkUpdateExcludeForm::buildForm in Bulk Update Fields 8.2

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/BulkUpdateExcludeForm.php, line 84

Class

BulkUpdateExcludeForm
Class BulkUpdateExcludeForm.

Namespace

Drupal\bulk_update_fields\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('bulk_update_fields.settings');
  $excluded_base_fields = [
    'nid',
    'uuid',
    'vid',
    'type',
    'revision_uid',
    'title',
    'menu_link',
    'status',
    'uid',
    'default_langcode',
    'revision_timestamp',
    'revision_log',
    'created',
    'changed',
    'pass',
    'name',
    'mail',
    'init',
  ];
  $options = [];
  $bundles = $this
    ->getFields('node');
  foreach ($bundles as $bundle) {
    foreach ($bundle as $field) {
      if (!in_array($field
        ->getName(), $excluded_base_fields) && !isset($options[$field
        ->getName()])) {
        $options[$field
          ->getName()]['field_name'] = $field
          ->getLabel() . ' (' . $field
          ->getName() . ')';
      }
    }
  }
  $header = [
    'field_name' => $this
      ->t('Field Name'),
  ];
  $form['table'] = [
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#default_value' => $config
      ->get('exclude') ? $config
      ->get('exclude') : '',
    '#empty' => $this
      ->t('No fields found'),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  ];
  return $form;
}