当前位置: 首页>>代码示例>>PHP>>正文


PHP DateFormatter::formatInterval方法代码示例

本文整理汇总了PHP中Drupal\Core\Datetime\DateFormatter::formatInterval方法的典型用法代码示例。如果您正苦于以下问题:PHP DateFormatter::formatInterval方法的具体用法?PHP DateFormatter::formatInterval怎么用?PHP DateFormatter::formatInterval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Datetime\DateFormatter的用法示例。


在下文中一共展示了DateFormatter::formatInterval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('xmlsitemap.settings');
     $intervals = array(300, 900, 1800, 3600, 10800, 21600, 43200, 86400, 172800, 259200, 604800);
     $intervals = array_combine($intervals, $intervals);
     $format_intervals = array();
     foreach ($intervals as $key => $value) {
         $format_intervals[$key] = $this->date->formatInterval($key);
     }
     $form['minimum_lifetime'] = array('#type' => 'select', '#title' => t('Minimum sitemap lifetime'), '#options' => array(0 => t('No minimum')) + $format_intervals, '#description' => t('The minimum amount of time that will elapse before the sitemaps are regenerated. The sitemaps will also only be regenerated on cron if any links have been added, updated, or deleted.') . '<br />' . t('Recommended value: %value.', array('%value' => t('1 day'))), '#default_value' => $config->get('minimum_lifetime'));
     $form['xsl'] = array('#type' => 'checkbox', '#title' => t('Include a stylesheet in the sitemaps for humans.'), '#description' => t('When enabled, this will add formatting and tables with sorting to make it easier to view the XML sitemap data instead of viewing raw XML output. Search engines will ignore this.'), '#default_value' => $config->get('xsl'));
     $form['prefetch_aliases'] = array('#type' => 'checkbox', '#title' => t('Prefetch URL aliases during sitemap generation.'), '#description' => t('When enabled, this will fetch all URL aliases at once instead of one at a time during sitemap generation. For medium or large sites, it is recommended to disable this feature as it uses a lot of memory.'), '#default_value' => $config->get('prefetch_aliases'));
     $form['advanced'] = array('#type' => 'details', '#title' => t('Advanced settings'), '#collapsible' => TRUE, '#collapsed' => !$this->state->get('xmlsitemap_developer_mode'), '#weight' => 10);
     $form['advanced']['gz'] = array('#type' => 'checkbox', '#title' => t('Generate additional compressed sitemaps using gzip.'), '#default_value' => $config->get('gz'), '#disabled' => !function_exists('gzencode'));
     $chunk_sizes = array(100, 500, 1000, 2500, 5000, 10000, 25000, XMLSITEMAP_MAX_SITEMAP_LINKS);
     $form['advanced']['chunk_size'] = array('#type' => 'select', '#title' => t('Number of links in each sitemap page'), '#options' => array('auto' => t('Automatic (recommended)')) + array_combine($chunk_sizes, $chunk_sizes), '#default_value' => xmlsitemap_var('chunk_size'), '#description' => t('If there are problems with rebuilding the sitemap, you may want to manually set this value. If you have more than @max links, an index with multiple sitemap pages will be generated. There is a maximum of @max sitemap pages.', array('@max' => XMLSITEMAP_MAX_SITEMAP_LINKS)));
     $batch_limits = array(5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000);
     $form['advanced']['batch_limit'] = array('#type' => 'select', '#title' => t('Maximum number of sitemap links to process at once'), '#options' => array_combine($batch_limits, $batch_limits), '#default_value' => xmlsitemap_var('batch_limit'), '#description' => t('If you have problems running cron or rebuilding the sitemap, you may want to lower this value.'));
     if (!xmlsitemap_check_directory()) {
         $form_state->setErrorByName('path', t('The directory %directory does not exist or is not writable.', array('%directory' => xmlsitemap_get_directory())));
     }
     $form['advanced']['path'] = array('#type' => 'textfield', '#title' => t('Sitemap cache directory'), '#default_value' => $config->get('path'), '#size' => 30, '#maxlength' => 255, '#description' => t('Subdirectory where the sitemap data will be stored. This folder <strong>must not be shared</strong> with any other Drupal site or install using XML sitemap.'), '#field_prefix' => file_build_uri(''), '#required' => TRUE);
     $form['advanced']['xmlsitemap_base_url'] = array('#type' => 'textfield', '#title' => t('Default base URL'), '#default_value' => $this->state->get('xmlsitemap_base_url'), '#size' => 30, '#description' => t('This is the default base URL used for sitemaps and sitemap links.'), '#required' => TRUE);
     $form['advanced']['lastmod_format'] = array('#type' => 'select', '#title' => t('Last modification date format'), '#options' => array(XMLSITEMAP_LASTMOD_SHORT => t('Short'), XMLSITEMAP_LASTMOD_MEDIUM => t('Medium'), XMLSITEMAP_LASTMOD_LONG => t('Long')), '#default_value' => $config->get('lastmod_format'));
     foreach ($form['advanced']['lastmod_format']['#options'] as $key => &$label) {
         $label .= ' (' . gmdate($key, REQUEST_TIME) . ')';
     }
     $form['advanced']['xmlsitemap_developer_mode'] = array('#type' => 'checkbox', '#title' => t('Enable developer mode to expose additional settings.'), '#default_value' => $this->state->get('xmlsitemap_developer_mode'));
     $form['xmlsitemap_settings'] = array('#type' => 'vertical_tabs', '#weight' => 20);
     $entities = xmlsitemap_get_link_info(NULL, TRUE);
     foreach ($entities as $entity => $entity_info) {
         $form[$entity] = array('#type' => 'details', '#title' => $entity_info['label'], '#collapsible' => TRUE, '#collapsed' => TRUE, '#group' => 'xmlsitemap_settings');
         if (!empty($entity_info['bundles'])) {
             // If this entity has bundles, show a bundle setting summary.
             xmlsitemap_add_form_entity_summary($form[$entity], $entity, $entity_info);
         }
         if (!empty($entity_info['xmlsitemap']['settings callback'])) {
             // Add any entity-specific settings.
             $entity_info['xmlsitemap']['settings callback']($form[$entity]);
         }
         // Ensure that the entity fieldset is not shown if there are no accessible
         // sub-elements.
         $form[$entity]['#access'] = (bool) Element::getVisibleChildren($form[$entity]);
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:49,代码来源:XmlSitemapSettingsForm.php

示例2: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     foreach ($items as $delta => $item) {
         if ($item->value) {
             $updated = $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $item->value)));
         } else {
             $updated = $this->t('never');
         }
         $elements[$delta] = array('#markup' => $updated);
     }
     return $elements;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:16,代码来源:TimestampAgoFormatter.php

示例3: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $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);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:16,代码来源:CronForm.php

示例4: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $form['num'] = array('#type' => 'number', '#title' => $this->t('How many users would you like to generate?'), '#default_value' => $this->getSetting('num'), '#required' => TRUE, '#min' => 0);
     $form['kill'] = array('#type' => 'checkbox', '#title' => $this->t('Delete all users (except user id 1) before generating new users.'), '#default_value' => $this->getSetting('kill'));
     $options = user_role_names(TRUE);
     unset($options[DRUPAL_AUTHENTICATED_RID]);
     $form['roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Which roles should the users receive?'), '#description' => $this->t('Users always receive the <em>authenticated user</em> role.'), '#options' => $options);
     $form['pass'] = array('#type' => 'textfield', '#title' => $this->t('Password to be set'), '#default_value' => $this->getSetting('pass'), '#size' => 32, '#description' => $this->t('Leave this field empty if you do not need to set a password'));
     $options = array(1 => $this->t('Now'));
     foreach (array(3600, 86400, 604800, 2592000, 31536000) as $interval) {
         $options[$interval] = $this->dateFormatter->formatInterval($interval, 1) . ' ' . $this->t('ago');
     }
     $form['time_range'] = array('#type' => 'select', '#title' => $this->t('How old should user accounts be?'), '#description' => $this->t('User ages will be distributed randomly from the current time, back to the selected time.'), '#options' => $options, '#default_value' => 604800);
     return $form;
 }
开发者ID:KenG01,项目名称:Achieve-D8,代码行数:18,代码来源:UserDevelGenerate.php

示例5: adminOverview

 /**
  * 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();
     /** @var \Drupal\aggregator\FeedInterface[] $feeds */
     foreach ($feeds as $feed) {
         $row = array();
         $row[] = $feed->link();
         $row[] = $this->formatPlural($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');
         if (!$last_checked && $refresh_rate) {
             $next_update = $this->t('imminently');
         } elseif ($last_checked && $refresh_rate) {
             $next_update = $next = $this->t('%time left', array('%time' => $this->dateFormatter->formatInterval($last_checked + $refresh_rate - REQUEST_TIME)));
         } else {
             $next_update = $this->t('never');
         }
         $row[] = $next_update;
         $links['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('entity.aggregator_feed.edit_form', ['aggregator_feed' => $feed->id()])];
         $links['delete'] = array('title' => $this->t('Delete'), 'url' => Url::fromRoute('entity.aggregator_feed.delete_form', ['aggregator_feed' => $feed->id()]));
         $links['delete_items'] = array('title' => $this->t('Delete items'), 'url' => Url::fromRoute('aggregator.feed_items_delete', ['aggregator_feed' => $feed->id()]));
         $links['update'] = array('title' => $this->t('Update items'), 'url' => Url::fromRoute('aggregator.feed_refresh', ['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;
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:38,代码来源:AggregatorController.php

示例6: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $bundles = $this->mediaBundleStorage->loadMultiple();
     if (empty($bundles)) {
         $create_url = $this->urlGenerator->generateFromRoute('media.bundle_add');
         $this->setMessage($this->t('You do not have any media bundles that can be generated. <a href="@create-bundle">Go create a new media bundle</a>', ['@create-bundle' => $create_url]), 'error', FALSE);
         return [];
     }
     $options = [];
     foreach ($bundles as $bundle) {
         $options[$bundle->id()] = ['bundle' => ['#markup' => $bundle->label()]];
     }
     $form['media_bundles'] = ['#type' => 'tableselect', '#header' => ['bundle' => $this->t('Media bundle')], '#options' => $options];
     $form['kill'] = ['#type' => 'checkbox', '#title' => $this->t('<strong>Delete all media</strong> in these bundles before generating new media.'), '#default_value' => $this->getSetting('kill')];
     $form['num'] = ['#type' => 'number', '#title' => $this->t('How many media items would you like to generate?'), '#default_value' => $this->getSetting('num'), '#required' => TRUE, '#min' => 0];
     $options = [1 => $this->t('Now')];
     foreach ([3600, 86400, 604800, 2592000, 31536000] as $interval) {
         $options[$interval] = $this->dateFormatter->formatInterval($interval, 1) . ' ' . $this->t('ago');
     }
     $form['time_range'] = ['#type' => 'select', '#title' => $this->t('How far back in time should the media be dated?'), '#description' => $this->t('Media creation dates will be distributed randomly from the current time, back to the selected time.'), '#options' => $options, '#default_value' => 604800];
     $form['name_length'] = ['#type' => 'number', '#title' => $this->t('Maximum number of words in names'), '#default_value' => $this->getSetting('name_length'), '#required' => TRUE, '#min' => 1, '#max' => 255];
     $options = [];
     // We always need a language.
     $languages = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
     foreach ($languages as $langcode => $language) {
         $options[$langcode] = $language->getName();
     }
     $form['add_language'] = ['#type' => 'select', '#title' => $this->t('Set language on media'), '#multiple' => TRUE, '#description' => $this->t('Requires locale.module'), '#options' => $options, '#default_value' => [$this->languageManager->getDefaultLanguage()->getId()]];
     $form['#redirect'] = FALSE;
     return $form;
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:34,代码来源:MediaDevelGenerate.php

示例7: buildConfigurationForm

 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $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' => $this->url('system.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;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:28,代码来源:DefaultProcessor.php

示例8: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $types = $this->nodeTypeStorage->loadMultiple();
     if (empty($types)) {
         $create_url = $this->urlGenerator->generateFromRoute('node.type_add');
         $this->setMessage($this->t('You do not have any content types that can be generated. <a href="@create-type">Go create a new content type</a>', array('@create-type' => $create_url)), 'error', FALSE);
         return;
     }
     $options = array();
     foreach ($types as $type) {
         $options[$type->id()] = array('type' => array('#markup' => $type->label()));
         if ($this->commentManager) {
             $comment_fields = $this->commentManager->getFields('node');
             $map = array($this->t('Hidden'), $this->t('Closed'), $this->t('Open'));
             $fields = array();
             foreach ($comment_fields as $field_name => $info) {
                 // Find all comment fields for the bundle.
                 if (in_array($type->id(), $info['bundles'])) {
                     $instance = FieldConfig::loadByName('node', $type->id(), $field_name);
                     $default_value = $instance->getDefaultValueLiteral();
                     $default_mode = reset($default_value);
                     $fields[] = SafeMarkup::format('@field: !state', array('@field' => $instance->label(), '!state' => $map[$default_mode['status']]));
                 }
             }
             // @todo Refactor display of comment fields.
             if (!empty($fields)) {
                 $options[$type->id()]['comments'] = array('data' => array('#theme' => 'item_list', '#items' => $fields));
             } else {
                 $options[$type->id()]['comments'] = $this->t('No comment fields');
             }
         }
     }
     $header = array('type' => $this->t('Content type'));
     if ($this->commentManager) {
         $header['comments'] = array('data' => $this->t('Comments'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM));
     }
     $form['node_types'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options);
     $form['kill'] = array('#type' => 'checkbox', '#title' => $this->t('<strong>Delete all content</strong> in these content types before generating new content.'), '#default_value' => $this->getSetting('kill'));
     $form['num'] = array('#type' => 'number', '#title' => $this->t('How many nodes would you like to generate?'), '#default_value' => $this->getSetting('num'), '#required' => TRUE, '#min' => 0);
     $options = array(1 => $this->t('Now'));
     foreach (array(3600, 86400, 604800, 2592000, 31536000) as $interval) {
         $options[$interval] = $this->dateFormatter->formatInterval($interval, 1) . ' ' . $this->t('ago');
     }
     $form['time_range'] = array('#type' => 'select', '#title' => $this->t('How far back in time should the nodes be dated?'), '#description' => $this->t('Node creation dates will be distributed randomly from the current time, back to the selected time.'), '#options' => $options, '#default_value' => 604800);
     $form['max_comments'] = array('#type' => $this->moduleHandler->moduleExists('comment') ? 'number' : 'value', '#title' => $this->t('Maximum number of comments per node.'), '#description' => $this->t('You must also enable comments for the content types you are generating. Note that some nodes will randomly receive zero comments. Some will receive the max.'), '#default_value' => $this->getSetting('max_comments'), '#min' => 0, '#access' => $this->moduleHandler->moduleExists('comment'));
     $form['title_length'] = array('#type' => 'number', '#title' => $this->t('Maximum number of words in titles'), '#default_value' => $this->getSetting('title_length'), '#required' => TRUE, '#min' => 1, '#max' => 255);
     $form['add_alias'] = array('#type' => 'checkbox', '#disabled' => !$this->moduleHandler->moduleExists('path'), '#description' => $this->t('Requires path.module'), '#title' => $this->t('Add an url alias for each node.'), '#default_value' => FALSE);
     $form['add_statistics'] = array('#type' => 'checkbox', '#title' => $this->t('Add statistics for each node (node_counter table).'), '#default_value' => TRUE, '#access' => $this->moduleHandler->moduleExists('statistics'));
     $options = array();
     // We always need a language.
     $languages = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
     foreach ($languages as $langcode => $language) {
         $options[$langcode] = $language->getName();
     }
     $form['add_language'] = array('#type' => 'select', '#title' => $this->t('Set language on nodes'), '#multiple' => TRUE, '#description' => $this->t('Requires locale.module'), '#options' => $options, '#default_value' => array($this->languageManager->getDefaultLanguage()->getId()));
     $form['#redirect'] = FALSE;
     return $form;
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:61,代码来源:ContentDevelGenerate.php

示例9: contactFloodControl

 /**
  * 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();
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:ContactController.php

示例10: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $message = parent::validateForm($form, $form_state);
     // Check if flood control has been activated for sending emails.
     if (!$this->currentUser()->hasPermission('administer contact forms') && (!$message->isPersonal() || !$this->currentUser()->hasPermission('administer users'))) {
         $limit = $this->config('contact.settings')->get('flood.limit');
         $interval = $this->config('contact.settings')->get('flood.interval');
         if (!$this->flood->isAllowed('contact', $limit, $interval)) {
             $form_state->setErrorByName('', $this->t('You cannot send more than %limit messages in @interval. Try again later.', array('%limit' => $limit, '@interval' => $this->dateFormatter->formatInterval($interval))));
         }
     }
     return $message;
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:16,代码来源:MessageForm.php

示例11: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Build the list of support engines for the checkboxes options.
     $engines = xmlsitemap_engines_get_engine_info();
     $engine_options = array();
     foreach ($engines as $engine => $engine_info) {
         $engine_options[$engine] = $engine_info['name'];
     }
     asort($engine_options);
     $form['engines'] = array('#type' => 'checkboxes', '#title' => t('Submit the sitemap to the following engines'), '#default_value' => $this->config('xmlsitemap_engines.settings')->get('engines'), '#options' => $engine_options);
     $lifetimes = array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 604800 * 2, 604800 * 4);
     $lifetimes = array_combine($lifetimes, $lifetimes);
     $format_lifetimes = array();
     foreach ($lifetimes as $value) {
         $format_lifetimes[$value] = $this->date->formatInterval($value);
     }
     $form['minimum_lifetime'] = array('#type' => 'select', '#title' => t('Do not submit more often than every'), '#options' => $format_lifetimes, '#default_value' => $this->config('xmlsitemap_engines.settings')->get('minimum_lifetime'));
     $form['xmlsitemap_engines_submit_updated'] = array('#type' => 'checkbox', '#title' => t('Only submit if the sitemap has been updated since the last submission.'), '#default_value' => $this->state->get('xmlsitemap_engines_submit_updated'));
     $form['custom_urls'] = array('#type' => 'textarea', '#title' => t('Custom submission URLs'), '#description' => t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', array('%example-before' => 'http://example.com/ping?[sitemap]', '%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', Url::fromRoute('xmlsitemap.sitemap_xml', [], ['absolute' => TRUE])))), '#default_value' => $this->config('xmlsitemap_engines.settings')->get('custom_urls'), '#rows' => 2, '#wysiwyg' => FALSE);
     // Ensure the xmlsitemap_engines variable gets filterd to a simple array.
     $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
     return parent::buildForm($form, $form_state);
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:26,代码来源:XmlSitemapEnginesSettingsForm.php

示例12: buildRow

 /**
  * {@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[RoleInterface::AUTHENTICATED_ID]);
     $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);
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:21,代码来源:UserListBuilder.php

示例13: render

 /**
  * {@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 $this->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 $this->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 $this->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);
         }
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:39,代码来源:Date.php

示例14: adminOverview

 /**
  * 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' => 'entity.aggregator_feed.edit_form', 'route_parameters' => array('aggregator_feed' => $feed->id()));
         $links['delete'] = array('title' => $this->t('Delete'), 'route_name' => 'entity.aggregator_feed.delete_form', '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;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:30,代码来源:AggregatorController.php

示例15: summaryTitle

 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);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:6,代码来源:Time.php


注:本文中的Drupal\Core\Datetime\DateFormatter::formatInterval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。