RssFeedsForm.php 2.1 KB

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