Example #1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state)
 {
     $config = $this->config('system.cron');
     $form['description'] = array('#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>');
     $form['run'] = array('#type' => 'submit', '#value' => t('Run cron'), '#submit' => array(array($this, 'submitCron')));
     $status = '<p>' . t('Last run: %cron-last ago.', array('%cron-last' => $this->dateFormatter->formatInterval(REQUEST_TIME - $this->state->get('system.cron_last')))) . '</p>';
     $form['status'] = array('#markup' => $status);
     $form['cron_url'] = array('#markup' => '<p>' . t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron/' . $this->state->get('system.cron_key'), array('absolute' => TRUE)))) . '</p>');
     $form['cron'] = array('#title' => t('Cron settings'), '#type' => 'details', '#open' => TRUE);
     $options = array(3600, 10800, 21600, 43200, 86400, 604800);
     $form['cron']['cron_safe_threshold'] = array('#type' => 'select', '#title' => t('Run cron every'), '#description' => t('More information about setting up scheduled tasks can be found by <a href="@url">reading the cron tutorial on drupal.org</a>.', array('@url' => url('http://drupal.org/cron'))), '#default_value' => $config->get('threshold.autorun'), '#options' => array(0 => t('Never')) + array_map(array($this->dateFormatter, 'formatInterval'), array_combine($options, $options)));
     return parent::buildForm($form, $form_state);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, array &$form_state)
 {
     $processors = $this->configuration['processors'];
     $info = $this->getPluginDefinition();
     $counts = array(3, 5, 10, 15, 20, 25);
     $items = array_map(function ($count) {
         return $this->dateFormatter->formatInterval($count, '1 item', '@count items');
     }, array_combine($counts, $counts));
     $intervals = array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800);
     $period = array_map(array($this->dateFormatter, 'formatInterval'), array_combine($intervals, $intervals));
     $period[AGGREGATOR_CLEAR_NEVER] = t('Never');
     $form['processors'][$info['id']] = array();
     // Only wrap into details if there is a basic configuration.
     if (isset($form['basic_conf'])) {
         $form['processors'][$info['id']] = array('#type' => 'details', '#title' => t('Default processor settings'), '#description' => $info['description'], '#open' => in_array($info['id'], $processors));
     }
     $form['processors'][$info['id']]['aggregator_summary_items'] = array('#type' => 'select', '#title' => t('Number of items shown in listing pages'), '#default_value' => $this->configuration['source']['list_max'], '#empty_value' => 0, '#options' => $items);
     $form['processors'][$info['id']]['aggregator_clear'] = array('#type' => 'select', '#title' => t('Discard items older than'), '#default_value' => $this->configuration['items']['expire'], '#options' => $period, '#description' => t('Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))));
     $lengths = array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000);
     $options = array_map(function ($length) {
         return $length == 0 ? t('Unlimited') : format_plural($length, '1 character', '@count characters');
     }, array_combine($lengths, $lengths));
     $form['processors'][$info['id']]['aggregator_teaser_length'] = array('#type' => 'select', '#title' => t('Length of trimmed description'), '#default_value' => $this->configuration['items']['teaser_length'], '#options' => $options, '#description' => t('The maximum number of characters used in the trimmed version of content.'));
     return $form;
 }
Example #3
0
 /**
  * Throws an exception if the current user triggers flood control.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  */
 protected function contactFloodControl()
 {
     $limit = $this->config('contact.settings')->get('flood.limit');
     $interval = $this->config('contact.settings')->get('flood.interval');
     if (!$this->flood->isAllowed('contact', $limit, $interval)) {
         drupal_set_message($this->t('You cannot send more than %limit messages in @interval. Try again later.', array('%limit' => $limit, '@interval' => $this->dateFormatter->formatInterval($interval))), 'error');
         throw new AccessDeniedHttpException();
     }
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['username']['data'] = array('#theme' => 'username', '#account' => $entity);
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('blocked');
     $roles = array_map('\\Drupal\\Component\\Utility\\String::checkPlain', user_role_names(TRUE));
     unset($roles[DRUPAL_AUTHENTICATED_RID]);
     $users_roles = array();
     foreach ($entity->getRoles() as $role) {
         if (isset($roles[$role])) {
             $users_roles[] = $roles[$role];
         }
     }
     asort($users_roles);
     $row['roles']['data'] = array('#theme' => 'item_list', '#items' => $users_roles);
     $row['member_for'] = $this->dateFormatter->formatInterval(REQUEST_TIME - $entity->getCreatedTime());
     $row['access'] = $entity->access ? $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $entity->getLastAccessedTime()))) : t('never');
     return $row + parent::buildRow($entity);
 }
Example #5
0
 /**
  * Displays the aggregator administration page.
  *
  * @return array
  *   A render array as expected by drupal_render().
  */
 public function adminOverview()
 {
     $entity_manager = $this->entityManager();
     $feeds = $entity_manager->getStorage('aggregator_feed')->loadMultiple();
     $header = array($this->t('Title'), $this->t('Items'), $this->t('Last update'), $this->t('Next update'), $this->t('Operations'));
     $rows = array();
     foreach ($feeds as $feed) {
         $row = array();
         $row[] = l($feed->label(), "aggregator/sources/" . $feed->id());
         $row[] = $this->dateFormatter->formatInterval($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
         $last_checked = $feed->getLastCheckedTime();
         $refresh_rate = $feed->getRefreshRate();
         $row[] = $last_checked ? $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $last_checked))) : $this->t('never');
         $row[] = $last_checked && $refresh_rate ? $this->t('%time left', array('%time' => $this->dateFormatter->formatInterval($last_checked + $refresh_rate - REQUEST_TIME))) : $this->t('never');
         $links['edit'] = array('title' => $this->t('Edit'), 'route_name' => 'aggregator.feed_configure', 'route_parameters' => array('aggregator_feed' => $feed->id()));
         $links['delete'] = array('title' => $this->t('Delete'), 'route_name' => 'aggregator.feed_delete', 'route_parameters' => array('aggregator_feed' => $feed->id()));
         $links['delete_items'] = array('title' => $this->t('Delete items'), 'route_name' => 'aggregator.feed_items_delete', 'route_parameters' => array('aggregator_feed' => $feed->id()));
         $links['update'] = array('title' => $this->t('Update items'), 'route_name' => 'aggregator.feed_refresh', 'route_parameters' => array('aggregator_feed' => $feed->id()));
         $row[] = array('data' => array('#type' => 'operations', '#links' => $links));
         $rows[] = $row;
     }
     $build['feeds'] = array('#prefix' => '<h3>' . $this->t('Feed overview') . '</h3>', '#type' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => $this->t('No feeds available. <a href="@link">Add feed</a>.', array('@link' => $this->url('aggregator.feed_add'))));
     return $build;
 }
Example #6
0
File: Date.php Project: shumer/blog
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $value = $this->getValue($values);
     $format = $this->options['date_format'];
     if (in_array($format, array('custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'))) {
         $custom_format = $this->options['custom_date_format'];
     }
     if ($value) {
         $timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
         $time_diff = REQUEST_TIME - $value;
         // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
         switch ($format) {
             case 'raw time ago':
                 return $this->dateFormatter->formatInterval($time_diff, is_numeric($custom_format) ? $custom_format : 2);
             case 'time ago':
                 return t('%time ago', array('%time' => $this->dateFormatter->formatInterval($time_diff, is_numeric($custom_format) ? $custom_format : 2)));
             case 'raw time hence':
                 return $this->dateFormatter->formatInterval(-$time_diff, is_numeric($custom_format) ? $custom_format : 2);
             case 'time hence':
                 return t('%time hence', array('%time' => $this->dateFormatter->formatInterval(-$time_diff, is_numeric($custom_format) ? $custom_format : 2)));
             case 'raw time span':
                 return ($time_diff < 0 ? '-' : '') . $this->dateFormatter->formatInterval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
             case 'inverse time span':
                 return ($time_diff > 0 ? '-' : '') . $this->dateFormatter->formatInterval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
             case 'time span':
                 return t($time_diff < 0 ? '%time hence' : '%time ago', array('%time' => $this->dateFormatter->formatInterval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2)));
             case 'custom':
                 if ($custom_format == 'r') {
                     return format_date($value, $format, $custom_format, $timezone, 'en');
                 }
                 return format_date($value, $format, $custom_format, $timezone);
             default:
                 return format_date($value, $format, '', $timezone);
         }
     }
 }
Example #7
0
File: Time.php Project: shumer/blog
 public function summaryTitle()
 {
     $results_lifespan = $this->getLifespan('results');
     $output_lifespan = $this->getLifespan('output');
     return $this->dateFormatter->formatInterval($results_lifespan, 1) . '/' . $this->dateFormatter->formatInterval($output_lifespan, 1);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, array &$form_state)
 {
     $view = $this->entity;
     $display_id = $this->displayID;
     // Do not allow the form to be cached, because $form_state['view'] can become
     // stale between page requests.
     // See views_ui_ajax_get_form() for how this affects #ajax.
     // @todo To remove this and allow the form to be cacheable:
     //   - Change $form_state['view'] to $form_state['temporary']['view'].
     //   - Add a #process function to initialize $form_state['temporary']['view']
     //     on cached form submissions.
     //   - Use form_load_include().
     $form_state['no_cache'] = TRUE;
     if ($display_id) {
         if (!$view->getExecutable()->setDisplay($display_id)) {
             $form['#markup'] = $this->t('Invalid display id @display', array('@display' => $display_id));
             return $form;
         }
     }
     $form['#tree'] = TRUE;
     $form['#attached']['library'][] = 'core/jquery.ui.tabs';
     $form['#attached']['library'][] = 'core/jquery.ui.dialog';
     $form['#attached']['library'][] = 'core/drupal.states';
     $form['#attached']['library'][] = 'core/drupal.tabledrag';
     if (!\Drupal::config('views.settings')->get('no_javascript')) {
         $form['#attached']['library'][] = 'views_ui/views_ui.admin';
     }
     $form['#attached']['css'] = static::getAdminCSS();
     $form['#attached']['js'][] = array('data' => array('views' => array('ajax' => array('id' => '#views-ajax-body', 'title' => '#views-ajax-title', 'popup' => '#views-ajax-popup', 'defaultForm' => $view->getDefaultAJAXMessage()))), 'type' => 'setting');
     $form += array('#prefix' => '', '#suffix' => '');
     $view_status = $view->status() ? 'enabled' : 'disabled';
     $form['#prefix'] .= '<div class="views-edit-view views-admin ' . $view_status . ' clearfix">';
     $form['#suffix'] = '</div>' . $form['#suffix'];
     $form['#attributes']['class'] = array('form-edit');
     if ($view->isLocked()) {
         $username = array('#theme' => 'username', '#account' => user_load($view->lock->owner));
         $lock_message_substitutions = array('!user' => drupal_render($username), '!age' => $this->dateFormatter->formatInterval(REQUEST_TIME - $view->lock->updated), '!break' => $view->url('break-lock'));
         $form['locked'] = array('#type' => 'container', '#attributes' => array('class' => array('view-locked', 'messages', 'messages--warning')), '#children' => $this->t('This view is being edited by user !user, and is therefore locked from editing by others. This lock is !age old. Click here to <a href="!break">break this lock</a>.', $lock_message_substitutions), '#weight' => -10);
     } else {
         $form['changed'] = array('#type' => 'container', '#attributes' => array('class' => array('view-changed', 'messages', 'messages--warning')), '#children' => $this->t('You have unsaved changes.'), '#weight' => -10);
         if (empty($view->changed)) {
             $form['changed']['#attributes']['class'][] = 'js-hide';
         }
     }
     $form['displays'] = array('#prefix' => '<h1 class="unit-title clearfix">' . $this->t('Displays') . '</h1>', '#type' => 'container', '#attributes' => array('class' => array('views-displays')));
     $form['displays']['top'] = $this->renderDisplayTop($view);
     // The rest requires a display to be selected.
     if ($display_id) {
         $form_state['display_id'] = $display_id;
         // The part of the page where editing will take place.
         $form['displays']['settings'] = array('#type' => 'container', '#id' => 'edit-display-settings');
         // Add a text that the display is disabled.
         if ($view->getExecutable()->displayHandlers->has($display_id)) {
             if (!$view->getExecutable()->displayHandlers->get($display_id)->isEnabled()) {
                 $form['displays']['settings']['disabled']['#markup'] = $this->t('This display is disabled.');
             }
         }
         // Add the edit display content
         $tab_content = $this->getDisplayTab($view);
         $tab_content['#theme_wrappers'] = array('container');
         $tab_content['#attributes'] = array('class' => array('views-display-tab'));
         $tab_content['#id'] = 'views-tab-' . $display_id;
         // Mark deleted displays as such.
         $display = $view->get('display');
         if (!empty($display[$display_id]['deleted'])) {
             $tab_content['#attributes']['class'][] = 'views-display-deleted';
         }
         // Mark disabled displays as such.
         if ($view->getExecutable()->displayHandlers->has($display_id) && !$view->getExecutable()->displayHandlers->get($display_id)->isEnabled()) {
             $tab_content['#attributes']['class'][] = 'views-display-disabled';
         }
         $form['displays']['settings']['settings_content'] = array('#type' => 'container', 'tab_content' => $tab_content);
         // The content of the popup dialog.
         $form['ajax-area'] = array('#type' => 'container', '#id' => 'views-ajax-popup');
         $form['ajax-area']['ajax-title'] = array('#markup' => '<div id="views-ajax-title"></div>');
         $form['ajax-area']['ajax-body'] = array('#type' => 'container', '#id' => 'views-ajax-body', '#children' => $view->getDefaultAJAXMessage());
     }
     return $form;
 }
Example #9
0
 /**
  * Tests the formatInterval method for 0 second.
  */
 public function testFormatIntervalZeroSecond()
 {
     $this->stringTranslation->expects($this->once())->method('translate')->with('0 sec', array(), array('langcode' => 'xxx-lolspeak'))->will($this->returnValue('0 sec'));
     $result = $this->date->formatInterval(0, 1, 'xxx-lolspeak');
     $this->assertEquals('0 sec', $result);
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $value = $values->{$this->field_alias};
     return $this->dateFormatter->formatInterval($value, isset($this->options['granularity']) ? $this->options['granularity'] : 2);
 }