public function FeedFormController::form

Overrides Drupal\Core\Entity\EntityFormController::form().

Overrides EntityFormControllerNG::form

File

drupal/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php, line 21
Contains \Drupal\aggregator\FeedFormController.

Class

FeedFormController
Form controller for the aggregator feed edit forms.

Namespace

Drupal\aggregator

Code

public function form(array $form, array &$form_state) {
  $feed = $this->entity;
  $period = drupal_map_assoc(array(
    900,
    1800,
    3600,
    7200,
    10800,
    21600,
    32400,
    43200,
    64800,
    86400,
    172800,
    259200,
    604800,
    1209600,
    2419200,
  ), 'format_interval');
  $period[AGGREGATOR_CLEAR_NEVER] = t('Never');
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $feed
      ->label(),
    '#maxlength' => 255,
    '#description' => t('The name of the feed (or the name of the website providing the feed).'),
    '#required' => TRUE,
  );
  $form['langcode'] = array(
    '#title' => t('Language'),
    '#type' => 'language_select',
    '#default_value' => $feed
      ->language()->langcode,
    '#languages' => Language::STATE_ALL,
  );
  $form['url'] = array(
    '#type' => 'url',
    '#title' => t('URL'),
    '#default_value' => $feed->url->value,
    '#maxlength' => NULL,
    '#description' => t('The fully-qualified URL of the feed.'),
    '#required' => TRUE,
  );
  $form['refresh'] = array(
    '#type' => 'select',
    '#title' => t('Update interval'),
    '#default_value' => $feed->refresh->value,
    '#options' => $period,
    '#description' => t('The length of time between feed updates. Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array(
      '@cron' => url('admin/reports/status'),
    )),
  );
  $form['block'] = array(
    '#type' => 'select',
    '#title' => t('News items in block'),
    '#default_value' => $feed->block->value,
    '#options' => drupal_map_assoc(array(
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9,
      10,
      11,
      12,
      13,
      14,
      15,
      16,
      17,
      18,
      19,
      20,
    )),
    '#description' => t("Drupal can make a block with the most recent news items of this feed. You can <a href=\"@block-admin\">configure blocks</a> to be displayed in the sidebar of your page. This setting lets you configure the number of news items to show in this feed's block. If you choose '0' this feed's block will be disabled.", array(
      '@block-admin' => url('admin/structure/block'),
    )),
  );

  // Handling of categories.
  $options = array();
  $values = array();
  $categories = db_query('SELECT c.cid, c.title FROM {aggregator_category} c ORDER BY title');
  foreach ($categories as $category) {
    $options[$category->cid] = check_plain($category->title);
    if (!empty($feed->categories) && in_array($category->cid, array_keys($feed->categories))) {
      $values[] = $category->cid;
    }
  }
  if ($options) {
    $form['category'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Categorize news items'),
      '#default_value' => $values,
      '#options' => $options,
      '#description' => t('New feed items are automatically filed in the checked categories.'),
    );
  }
  return parent::form($form, $form_state, $feed);
}