Version 1
[yaffs-website] / web / core / modules / system / src / Form / RssFeedsForm.php
1 <?php
2
3 namespace Drupal\system\Form;
4
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Configure RSS settings for this site.
10  */
11 class RssFeedsForm extends ConfigFormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'system_rss_feeds_settings';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function getEditableConfigNames() {
24     return ['system.rss'];
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function buildForm(array $form, FormStateInterface $form_state) {
31     $rss_config = $this->config('system.rss');
32     $form['feed_description'] = [
33       '#type' => 'textarea',
34       '#title' => t('Feed description'),
35       '#default_value' => $rss_config->get('channel.description'),
36       '#description' => t('Description of your site, included in each feed.')
37     ];
38     $options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30];
39     $form['feed_default_items'] = [
40       '#type' => 'select',
41       '#title' => t('Number of items in each feed'),
42       '#default_value' => $rss_config->get('items.limit'),
43       '#options' => array_combine($options, $options),
44       '#description' => t('Default number of items to include in each feed.')
45     ];
46     $form['feed_view_mode'] = [
47       '#type' => 'select',
48       '#title' => t('Feed content'),
49       '#default_value' => $rss_config->get('items.view_mode'),
50       '#options' => [
51         'title' => t('Titles only'),
52         'teaser' => t('Titles plus teaser'),
53         'fulltext' => t('Full text'),
54       ],
55       '#description' => t('Global setting for the default display of content items in each feed.')
56     ];
57
58     return parent::buildForm($form, $form_state);
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function submitForm(array &$form, FormStateInterface $form_state) {
65     $this->config('system.rss')
66       ->set('channel.description', $form_state->getValue('feed_description'))
67       ->set('items.limit', $form_state->getValue('feed_default_items'))
68       ->set('items.view_mode', $form_state->getValue('feed_view_mode'))
69       ->save();
70
71     parent::submitForm($form, $form_state);
72   }
73
74 }