RobotsTxtAdminSettingsForm.php in RobotsTxt 8
File
src/Form/RobotsTxtAdminSettingsForm.php
View source
<?php
namespace Drupal\robotstxt\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Cache\Cache;
class RobotsTxtAdminSettingsForm extends ConfigFormBase {
public function getFormId() {
return 'robotstxt_admin_settings';
}
protected function getEditableConfigNames() {
return [
'robotstxt.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('robotstxt.settings');
$form['robotstxt_content'] = [
'#type' => 'textarea',
'#title' => $this
->t('Contents of robots.txt'),
'#default_value' => $config
->get('content'),
'#cols' => 60,
'#rows' => 20,
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('robotstxt.settings');
$config
->set('content', $form_state
->getValue('robotstxt_content'))
->save();
Cache::invalidateTags([
'robotstxt',
]);
parent::submitForm($form, $form_state);
}
}