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