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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 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 ; } |
Please login to continue.