class SettingsForm in Save & Edit 8
Class SettingsForm.
@package Drupal\save_edit\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\save_edit\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
1 string reference to 'SettingsForm'
File
- src/
Form/ SettingsForm.php, line 14
Namespace
Drupal\save_edit\FormView source
class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'save_edit.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'save_edit_settings_form';
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('save_edit.settings')
->set('button_value', $form_state
->getValue('button_value'))
->set('button_weight', $form_state
->getValue('button_weight'))
->set('dropbutton', $form_state
->getValue('dropbutton'))
->set('hide_default_save', $form_state
->getValue('hide_default_save'))
->set('hide_default_publish', $form_state
->getValue('hide_default_publish'))
->set('hide_default_preview', $form_state
->getValue('hide_default_preview'))
->set('hide_default_delete', $form_state
->getValue('hide_default_delete'))
->set('unpublish', $form_state
->getValue('unpublish'))
->set('unpublish_new_only', $form_state
->getValue('unpublish_new_only'))
->set('node_types', $form_state
->getValue('node_types'))
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |