class SimpleNodeImporterConfigForm in Simple Node Importer 8
Configuration Form for the Simple Node Importer.
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\simple_node_importer\Form\SimpleNodeImporterConfigForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SimpleNodeImporterConfigForm
1 string reference to 'SimpleNodeImporterConfigForm'
File
- src/
Form/ SimpleNodeImporterConfigForm.php, line 12
Namespace
Drupal\simple_node_importer\FormView source
class SimpleNodeImporterConfigForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'simple_node_importer_config_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'simple_node_importer.settings',
];
}
protected $contentTypes;
/**
* Constructs variables.
*
* @var array $contentTypes
* The information from the GetContentTypes service for this form.
* @var bool $checkAvailablity
* To check the availability of Content Type exists or not.
*/
public function __construct($contentTypes, $checkAvailablity) {
$this->contentTypes = $contentTypes;
$this->checkAvailablity = $checkAvailablity;
}
/**
* Builds config form.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('simple_node_importer.settings');
$content_type_selected = [];
$content_type_select = $config
->get('content_type_select');
$entity_type_options = [
'node' => 'node',
'user' => 'user',
'taxonomy' => 'taxonomy',
];
if (!empty($content_type_select)) {
foreach ($content_type_select as $key => $value) {
if ($value) {
$content_type_selected[$key] = $value;
}
}
}
$form['fieldset_entity_type'] = [
'#type' => 'fieldset',
'#title' => $this
->t('entity type settings'),
'#weight' => 1,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
];
$form['fieldset_entity_type']['entity_type_select'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Select entity type'),
'#default_value' => $config
->get('entity_type_select'),
'#options' => $entity_type_options,
'#description' => $this
->t('Configuration for the entity type to be selected.'),
'#required' => FALSE,
];
$form['fieldset_content_type'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Content type settings'),
'#weight' => 1,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#states' => [
'visible' => [
':input[name="entity_type_select[node]"]' => [
[
'checked' => TRUE,
],
],
],
],
];
$form['fieldset_content_type']['content_type_select'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Select content type'),
'#default_value' => isset($content_type_selected) ? $content_type_selected : NULL,
'#options' => $this->contentTypes,
'#description' => $this
->t('Configuration for the content type to be selected.'),
'#required' => FALSE,
];
$form['fieldset_user_auto_create_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('User Auto Creation Settings'),
'#weight' => 1,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
];
// The options to display in our form radio buttons.
$options = [
'admin' => $this
->t('Set Admin as default author.'),
'current' => $this
->t('Set current user as default author.'),
'new' => $this
->t('Create new user with authenticated role.'),
];
$form['fieldset_user_auto_create_settings']['simple_node_importer_allow_user_autocreate'] = [
'#type' => 'radios',
'#options' => $options,
'#default_value' => $config
->get('simple_node_importer_allow_user_autocreate'),
'#description' => $this
->t('User will be set accordingly, if the provided value for author in csv is not avaiable in the system.'),
];
$form['fieldset_taxonomy_term_type'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Taxonomy Term settings'),
'#weight' => 1,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
];
$form['fieldset_taxonomy_term_type']['simple_node_importer_allow_add_term'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow adding new taxonomy terms.'),
'#default_value' => $config
->get('simple_node_importer_allow_add_term'),
'#description' => $this
->t('Check to allow adding term for taxonomy reference fields, if term is not available.'),
];
$form['fieldset_remove_importer'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Node remove settings'),
'#weight' => 2,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
];
// The options to display in our checkboxes.
$option = [
'option' => $this
->t('Delete import logs.'),
];
$form['fieldset_remove_importer']['node_delete'] = [
'#title' => '',
'#type' => 'checkboxes',
'#description' => $this
->t('Select the checkbox to delete all import logs permanently.'),
'#options' => $option,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('simple_node_importer.settings');
$config
->set('entity_type_select', $form_state
->getValue('entity_type_select'))
->set('content_type_select', $form_state
->getValue('content_type_select'))
->set('simple_node_importer_allow_user_autocreate', $form_state
->getValue('simple_node_importer_allow_user_autocreate'))
->set('simple_node_importer_allow_add_term', $form_state
->getValue('simple_node_importer_allow_add_term'))
->set('node_delete', $form_state
->getValue('node_delete'))
->save();
if (method_exists($this, 'submitFormDeleteLogs')) {
$this
->submitFormDeleteLogs($form, $form_state);
}
parent::submitForm($form, $form_state);
}
/**
* Delete import logs.
*/
public function submitFormDeleteLogs(array &$form, FormStateInterface $form_state) {
if ($this->checkAvailablity) {
$node_setting = $form_state
->getValue([
'node_delete',
'deletelog',
]);
$bundle = 'simple_node';
$query = \Drupal::entityQuery('node');
$query
->condition('status', 1);
$query
->condition('type', $bundle);
$nids = $query
->execute();
if ($node_setting === 'deletelog' && !empty($nids)) {
entity_delete_multiple('node', $nids);
drupal_set_message($this
->t('%count nodes has been deleted.', [
'%count' => count($nids),
]));
}
elseif ($node_setting === 'deletelog' && empty($nids)) {
drupal_set_message($this
->t("Oops there is nothing to delete"));
}
}
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('snp.get_services')
->getContentTypeList(), $container
->get('snp.get_services')
->checkAvailablity());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
SimpleNodeImporterConfigForm:: |
protected | property | ||
SimpleNodeImporterConfigForm:: |
public | function |
Builds config form. Overrides ConfigFormBase:: |
|
SimpleNodeImporterConfigForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SimpleNodeImporterConfigForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SimpleNodeImporterConfigForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SimpleNodeImporterConfigForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SimpleNodeImporterConfigForm:: |
public | function | Delete import logs. | |
SimpleNodeImporterConfigForm:: |
public | function |
Constructs variables. 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. |