Repository URL to install this package:
|
Version:
2.0.1 ▾
|
<?php
namespace Drupal\dds\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class NoFollowForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'dds_utilities_nofollow_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'dds.utilities.nofollow_settings'
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('dds.utilities.nofollow_settings');
$form = [
'identical_paths' => [
'#type' => 'checkbox',
'#title' => $this->t('Identical nofollow and noindex paths.'),
'#default_value' => $config->get('identical_paths'),
],
'nofollow' => [
'#type' => 'textarea',
'#title' => $this->t('No follow'),
'#description' => $this->t('List of paths which will have nofollow added to them. Enter one path per line. Must have a leading slash and no trailing slash, like so: <em>/user/login</em>.'),
'#default_value' => $config->get('nofollow'),
'#states' => [
'visible' => [
':input[name="identical_paths"]' => ['checked' => FALSE],
]
]
],
'noindex' => [
'#type' => 'textarea',
'#title' => $this->t('No index'),
'#description' => $this->t('List of paths which will have noindex added to them. Enter one path per line. Must have a leading slash and no trailing slash, like so: <em>/user/login</em>.'),
'#default_value' => $config->get('noindex'),
'#states' => [
'visible' => [
':input[name="identical_paths"]' => ['checked' => FALSE],
]
]
],
'nofollow_noindex' => [
'#type' => 'textarea',
'#title' => $this->t('No follow and No index'),
'#description' => $this->t('List of paths which will have nofollow and noindex added to them. Enter one path per line. Must have a leading slash and no trailing slash, like so: <em>/user/login</em>.'),
'#default_value' => $config->get('nofollow_noindex'),
'#states' => [
'visible' => [
':input[name="identical_paths"]' => ['checked' => TRUE],
]
]
],
'submit' => [
'#type' => 'submit',
'#value' => $this->t('Save'),
]
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory->getEditable('dds.utilities.nofollow_settings')
->set('identical_paths', $form_state->getValue('identical_paths'))
->set('nofollow', $form_state->getValue('nofollow'))
->set('noindex', $form_state->getValue('noindex'))
->set('nofollow_noindex', $form_state->getValue('nofollow_noindex'))
->save();
parent::submitForm($form, $form_state);
}
}