public function ConfigEditor::buildForm in Devel 8
Same name and namespace in other branches
- 8.3 src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::buildForm()
- 8.2 src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::buildForm()
- 4.x src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::buildForm()
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 FormInterface::buildForm
File
- src/
Form/ ConfigEditor.php, line 27
Class
- ConfigEditor
- Edit config variable form.
Namespace
Drupal\devel\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $config_name = '') {
$config = $this
->config($config_name);
if ($config === FALSE || $config
->isNew()) {
drupal_set_message(t('Config @name does not exist in the system.', array(
'@name' => $config_name,
)), 'error');
return;
}
$data = $config
->getOriginal();
if (empty($data)) {
drupal_set_message(t('Config @name exists but has no data.', array(
'@name' => $config_name,
)), 'warning');
return;
}
try {
$output = Yaml::encode($data);
} catch (InvalidDataTypeException $e) {
drupal_set_message(t('Invalid data detected for @name : %error', array(
'@name' => $config_name,
'%error' => $e
->getMessage(),
)), 'error');
return;
}
$form['current'] = array(
'#type' => 'details',
'#title' => $this
->t('Current value for %variable', array(
'%variable' => $config_name,
)),
'#attributes' => array(
'class' => array(
'container-inline',
),
),
);
$form['current']['value'] = array(
'#type' => 'item',
'#markup' => dpr($output, TRUE),
);
$form['name'] = array(
'#type' => 'value',
'#value' => $config_name,
);
$form['new'] = array(
'#type' => 'textarea',
'#title' => $this
->t('New value'),
'#default_value' => $output,
'#rows' => 24,
'#required' => TRUE,
);
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => $this
->t('Cancel'),
'#url' => $this
->buildCancelLinkUrl(),
);
return $form;
}