You are here

public function CivicrmEntitySettings::buildForm in CiviCRM Entity 8.3

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/CivicrmEntitySettings.php, line 113

Class

CivicrmEntitySettings
Form for CiviCRM entity settings.

Namespace

Drupal\civicrm_entity\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $config = $this
    ->config('civicrm_entity.settings');
  $formats = filter_formats();
  $form['filter_format'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Text format'),
    '#options' => array_map(function (FilterFormatInterface $filter) {
      return $filter
        ->label();
    }, $formats),
    '#default_value' => $config
      ->get('filter_format') ?: filter_fallback_format(),
    '#access' => count($formats) > 1 && $this
      ->currentUser()
      ->hasPermission('administer filters'),
    '#attributes' => [
      'class' => [
        'filter-list',
      ],
    ],
  ];
  $civicrm_entity_types = SupportedEntities::getInfo();

  // @todo Use tableselect so we can display entity descriptions.
  $options = array_map(function (array $entity_info) {
    return $entity_info['civicrm entity label'];
  }, $civicrm_entity_types);
  asort($options);
  $form['enabled_entity_types'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Enabled entity types'),
    '#options' => $options,
    '#default_value' => $config
      ->get('enabled_entity_types'),
  ];
  $form['advanced_settings'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced settings'),
    '#open' => FALSE,
  ];
  $form['advanced_settings']['disable_hooks'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable pre/post hooks'),
    '#default_value' => $config
      ->get('disable_hooks'),
    '#description' => $this
      ->t('Not intended for normal use. Provided to temporarily disable Drupal entity hooks for CiviCRM Entity types for special cases, such as migrations. Only disable if you know you need to.'),
  ];
  return $form;
}