ConfigSingleImportForm::buildForm

public ConfigSingleImportForm::buildForm(array $form, FormStateInterface $form_state)

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 ConfirmFormBase::buildForm

File

core/modules/config/src/Form/ConfigSingleImportForm.php, line 216

Class

ConfigSingleImportForm
Provides a form for importing a single configuration file.

Namespace

Drupal\config\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  // When this is the confirmation step fall through to the confirmation form.
  if ($this->data) {
    return parent::buildForm($form, $form_state);
  }

  $entity_types = array();
  foreach ($this->entityManager->getDefinitions() as $entity_type => $definition) {
    if ($definition->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) {
      $entity_types[$entity_type] = $definition->getLabel();
    }
  }
  // Sort the entity types by label, then add the simple config to the top.
  uasort($entity_types, 'strnatcasecmp');
  $config_types = array(
    'system.simple' => $this->t('Simple configuration'),
  ) + $entity_types;
  $form['config_type'] = array(
    '#title' => $this->t('Configuration type'),
    '#type' => 'select',
    '#options' => $config_types,
    '#required' => TRUE,
  );
  $form['config_name'] = array(
    '#title' => $this->t('Configuration name'),
    '#description' => $this->t('Enter the name of the configuration file without the <em>.yml</em> extension. (e.g. <em>system.site</em>)'),
    '#type' => 'textfield',
    '#states' => array(
      'required' => array(
        ':input[name="config_type"]' => array('value' => 'system.simple'),
      ),
      'visible' => array(
        ':input[name="config_type"]' => array('value' => 'system.simple'),
      ),
    ),
  );
  $form['import'] = array(
    '#title' => $this->t('Paste your configuration here'),
    '#type' => 'textarea',
    '#rows' => 24,
    '#required' => TRUE,
  );
  $form['advanced'] = array(
    '#type' => 'details',
    '#title' => $this->t('Advanced'),
  );
  $form['advanced']['custom_entity_id'] = array(
    '#title' => $this->t('Custom Entity ID'),
    '#type' => 'textfield',
    '#description' => $this->t('Specify a custom entity ID. This will override the entity ID in the configuration above.'),
  );
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this->t('Import'),
    '#button_type' => 'primary',
  );
  return $form;
}
doc_Drupal
2016-10-29 08:54:27
Comments
Leave a Comment

Please login to continue.