public function SettingsForm::buildForm in Save & Edit 8
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/ SettingsForm.php, line 35
Class
- SettingsForm
- Class SettingsForm.
Namespace
Drupal\save_edit\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('save_edit.settings');
$weights_range = range(-10, 10);
$weights = array_combine($weights_range, $weights_range);
$form['button_value'] = [
'#type' => 'textfield',
'#title' => $this
->t('Text to use for Save & Edit button'),
'#description' => $this
->t('This is the default text that will be used for the button at the bottom of the node form.<br>It would be best to use familiar terms like "<strong>Save & Edit</strong>" or "<strong>Apply</strong>" so that users can easily understand the feature/function related to this option.'),
'#maxlength' => 64,
'#size' => 64,
'#default_value' => $config
->get('button_value'),
];
$form['button_weight'] = [
'#type' => 'select',
'#title' => $this
->t('Save & Edit Button Weight'),
'#description' => $this
->t('You can adjust the horizontal positioning in the button section (or vertical positioning when using the dropbutton setting).'),
'#options' => $weights,
'#default_value' => $config
->get('button_weight'),
];
$form['dropbutton'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Integrate into dropbutton'),
'#description' => $this
->t('This setting will insert the Save & Edit button into the save dropbutton.'),
'#default_value' => $config
->get('dropbutton'),
];
$form['unpublish'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Auto Unpublish All Nodes'),
'#description' => $this
->t('This setting will automatically uncheck the "Published" status when using <strong>Save & Edit</strong> button to save nodes.'),
'#default_value' => $config
->get('unpublish'),
];
$form['unpublish_new_only'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Auto Unpublish on New Nodes Only'),
'#description' => $this
->t('This will only mark the node as unpublished upon creating a new node. Assuming this is used, on subsequent uses of <strong>Save & Edit</strong> the node will be unpublished already, and NOT affected. You will be required at some point to manually publish the node using the optional <strong>Publish</strong> button, or manually ticking the appropriate checkbox when hitting the default Save button.'),
'#default_value' => $config
->get('unpublish_new_only'),
];
$form['hide_default_save'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hide default Save button'),
'#description' => $this
->t('This will hide the Save dropbutton.'),
'#default_value' => $config
->get('hide_default_save'),
];
$form['hide_default_publish'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hide the Publish button'),
'#default_value' => $config
->get('hide_default_publish'),
'#description' => $this
->t('This will hide the Publish button.'),
];
$form['hide_default_preview'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hide default Preview button'),
'#default_value' => $config
->get('hide_default_preview'),
'#description' => $this
->t('This will hide the Preview button.'),
];
$form['hide_default_delete'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hide default Delete button'),
'#default_value' => $config
->get('hide_default_delete'),
'#description' => $this
->t('This will hide the Delete button.'),
];
$node_types = NodeType::loadMultiple();
$keyed_node_types = [];
foreach ($node_types as $content_type) {
$keyed_node_types[$content_type
->id()] = $content_type
->label();
}
$default_value_node_types = $config
->get('node_types');
$form['node_types'] = [
'#type' => 'checkboxes',
'#options' => $keyed_node_types,
'#title' => $this
->t('Node types'),
'#description' => $this
->t('Set the node types you want to display links for.'),
'#default_value' => isset($default_value_node_types) ? $default_value_node_types : [],
];
return parent::buildForm($form, $form_state);
}