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


PHP DateFormatterInterface::format方法代码示例

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


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

示例1: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     /* @var \Drupal\commerce_product\Entity\Product $product */
     $product = $this->entity;
     $form = parent::form($form, $form_state);
     $form['#tree'] = TRUE;
     $form['#theme'] = ['product_form'];
     $form['#attached']['library'][] = 'commerce_product/form';
     $form['#entity_builders']['update_status'] = [$this, 'updateStatus'];
     // Changed must be sent to the client, for later overwrite error checking.
     $form['changed'] = ['#type' => 'hidden', '#default_value' => $product->getChangedTime()];
     $last_saved = t('Not saved yet');
     if (!$product->isNew()) {
         $last_saved = $this->dateFormatter->format($product->getChangedTime(), 'short');
     }
     $form['meta'] = ['#attributes' => ['class' => ['entity-meta__header']], '#type' => 'container', '#group' => 'advanced', '#weight' => -100, 'published' => ['#type' => 'html_tag', '#tag' => 'h3', '#value' => $product->isPublished() ? $this->t('Published') : $this->t('Not published'), '#access' => !$product->isNew(), '#attributes' => ['class' => 'entity-meta__title']], 'changed' => ['#type' => 'item', '#wrapper_attributes' => ['class' => ['entity-meta__last-saved', 'container-inline']], '#markup' => '<h4 class="label inline">' . $this->t('Last saved') . '</h4> ' . $last_saved], 'author' => ['#type' => 'item', '#wrapper_attributes' => ['class' => ['author', 'container-inline']], '#markup' => '<h4 class="label inline">' . $this->t('Author') . '</h4> ' . $product->getOwner()->getDisplayName()]];
     $form['advanced'] = ['#type' => 'container', '#attributes' => ['class' => ['entity-meta']], '#weight' => 99];
     $form['path_settings'] = ['#type' => 'details', '#title' => t('URL path settings'), '#open' => !empty($form['path']['widget'][0]['alias']['#value']), '#group' => 'advanced', '#access' => !empty($form['path']['#access']) && $product->get('path')->access('edit'), '#attributes' => ['class' => ['path-form']], '#attached' => ['library' => ['path/drupal.path']], '#weight' => 30];
     $form['author'] = ['#type' => 'details', '#title' => t('Authoring information'), '#group' => 'advanced', '#attributes' => ['class' => ['product-form-author']], '#attached' => ['library' => ['commerce_product/drupal.commerce_product']], '#weight' => 90, '#optional' => TRUE];
     if (isset($form['uid'])) {
         $form['uid']['#group'] = 'author';
     }
     if (isset($form['created'])) {
         $form['created']['#group'] = 'author';
     }
     if (isset($form['path'])) {
         $form['path']['#group'] = 'path_settings';
     }
     return $form;
 }
开发者ID:marmouset,项目名称:drupal,代码行数:33,代码来源:ProductForm.php

示例2: getArgument

 /**
  * Return the default argument.
  */
 public function getArgument()
 {
     $argument = $this->argument;
     // The Date argument handlers provide their own format strings, otherwise
     // use a default.
     if ($argument instanceof \Drupal\calendar_datetime\Plugin\views\argument\Date) {
         /** @var \Drupal\views\Plugin\views\argument\Date $argument */
         $format = $argument->getArgFormat();
     } else {
         $format = 'Y-m-d';
     }
     $request_time = $this->request->server->get('REQUEST_TIME');
     return $this->dateFormatter->format($request_time, 'custom', $format);
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:17,代码来源:Date.php

示例3: getResetPassForm

 /**
  * Returns the user password reset form.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param int $uid
  *   User ID of the user requesting reset.
  *
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  *   The form structure or a redirect response.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  *   If the pass_reset_timeout or pass_reset_hash are not available in the
  *   session. Or if $uid is for a blocked user or invalid user ID.
  */
 public function getResetPassForm(Request $request, $uid)
 {
     $session = $request->getSession();
     $timestamp = $session->get('pass_reset_timeout');
     $hash = $session->get('pass_reset_hash');
     // As soon as the session variables are used they are removed to prevent the
     // hash and timestamp from being leaked unexpectedly. This could occur if
     // the user does not click on the log in button on the form.
     $session->remove('pass_reset_timeout');
     $session->remove('pass_reset_hash');
     if (!$hash || !$timestamp) {
         throw new AccessDeniedHttpException();
     }
     /** @var \Drupal\user\UserInterface $user */
     $user = $this->userStorage->load($uid);
     if ($user === NULL || !$user->isActive()) {
         // Blocked or invalid user ID, so deny access. The parameters will be in
         // the watchdog's URL for the administrator to check.
         throw new AccessDeniedHttpException();
     }
     // Time out, in seconds, until login URL expires.
     $timeout = $this->config('user.settings')->get('password_reset_timeout');
     $expiration_date = $user->getLastLoginTime() ? $this->dateFormatter->format($timestamp + $timeout) : NULL;
     return $this->formBuilder()->getForm(UserPasswordResetForm::class, $user, $expiration_date, $timestamp, $hash);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:40,代码来源:UserController.php

示例4: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Replace all contiguous whitespaces (including tabs and newlines) with a
     // single plain space.
     $form_state->setValue(['date_format'], trim(preg_replace('/\\s+/', ' ', $form_state->getValue(['date_format']))));
     // Validate the letters used in the scheduler date format. All punctuation
     // is accepted, so remove everything except word characters then check that
     // there is nothing else which is not in the list of acceptable date/time
     // letters.
     $no_punctuation = preg_replace('/[^\\w+]/', '', $form_state->getValue(['date_format']));
     if (preg_match_all('/[^' . SCHEDULER_DATE_LETTERS . SCHEDULER_TIME_LETTERS . ']/', $no_punctuation, $extra)) {
         $form_state->setErrorByName('date_format', $this->t('You may only use the letters $date_letters for the date and $time_letters for the time. Remove the extra characters $extra', ['$date_letters' => SCHEDULER_DATE_LETTERS, '$time_letters' => SCHEDULER_TIME_LETTERS, '$extra' => implode(' ', $extra[0])]));
     }
     // If date-only is enabled then check if a valid default time was entered.
     // Leading zeros and seconds can be omitted, eg. 6:30 is considered valid.
     if ($form_state->getValue(['allow_date_only'])) {
         $default_time = date_parse($form_state->getValue(['default_time']));
         if ($default_time['error_count']) {
             $form_state->setErrorByName('default_time', $this->t('The default time should be in the format HH:MM:SS'));
         } else {
             // Insert any possibly omitted leading zeroes.
             $unix_time = mktime($default_time['hour'], $default_time['minute'], $default_time['second']);
             $form_state->setValue(['default_time'], $this->dateFormatter->format($unix_time, 'custom', 'H:i:s'));
         }
     }
     // Check that either the date format has a time part or the date-only option
     // is turned on.
     $time_format = $this->getTimeOnlyFormat($form_state->getValue(['date_format']));
     if ($time_format == '' && !$form_state->getValue(['allow_date_only'])) {
         $form_state->setErrorByName('date_format', $this->t('You must either include a time within the date format or enable the date-only option.'));
     }
 }
开发者ID:blakefrederick,项目名称:sas-backend,代码行数:35,代码来源:SchedulerAdminForm.php

示例5: filter

 /**
  * {@inheritdoc}
  */
 public function filter(DataDefinitionInterface $definition, $value, array $arguments, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     if ($definition->getDataType() != 'timestamp') {
         // Convert the date to an timestamp.
         $value = $this->getTypedDataManager()->create($definition, $value)->getDateTime()->getTimestamp();
     }
     $arguments += [0 => 'medium', 1 => '', 2 => NULL, 3 => NULL];
     if ($arguments[0] != 'custom' && $bubbleable_metadata) {
         $config = $this->dateFormatStorage->load($arguments[0]);
         if (!$config) {
             throw new \InvalidArgumentException("Unknown date format {$arguments['0']} given.");
         }
         $bubbleable_metadata->addCacheableDependency($config);
     }
     return $this->dateFormatter->format($value, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
 }
开发者ID:Progressable,项目名称:openway8,代码行数:19,代码来源:FormatDateFilter.php

示例6: getRevisionDescription

 /**
  * {@inheritdoc}
  */
 protected function getRevisionDescription(ContentEntityInterface $revision, $is_default = FALSE)
 {
     /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\user\EntityOwnerInterface|\Drupal\Core\Entity\RevisionLogInterface $revision */
     if ($revision instanceof RevisionLogInterface) {
         // Use revision link to link to revisions that are not active.
         $date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short');
         $link = $revision->toLink($date, 'revision');
         // @todo: Simplify this when https://www.drupal.org/node/2334319 lands.
         $username = ['#theme' => 'username', '#account' => $revision->getRevisionUser()];
         $username = $this->renderer->render($username);
     } else {
         $link = $revision->toLink($revision->label(), 'revision');
         $username = '';
     }
     $markup = '';
     if ($revision instanceof RevisionLogInterface) {
         $markup = $revision->getRevisionLogMessage();
     }
     if ($username) {
         $template = '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}';
     } else {
         $template = '{% trans %} {{ date }} {% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}';
     }
     $column = ['data' => ['#type' => 'inline_template', '#template' => $template, '#context' => ['date' => $link->toString(), 'username' => $username, 'message' => ['#markup' => $markup, '#allowed_tags' => Xss::getHtmlTagList()]]]];
     return $column;
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:29,代码来源:RevisionOverviewController.php

示例7: revisionOverview

 /**
  * Generates an overview table of older revisions of a node.
  *
  * @param \Drupal\node\NodeInterface $node
  *   A node object.
  *
  * @return array
  *   An array as expected by drupal_render().
  */
 public function revisionOverview(NodeInterface $node)
 {
     $account = $this->currentUser();
     $langcode = $node->language()->getId();
     $langname = $node->language()->getName();
     $languages = $node->getTranslationLanguages();
     $has_translations = count($languages) > 1;
     $node_storage = $this->entityManager()->getStorage('node');
     $type = $node->getType();
     $build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $node->label()]) : $this->t('Revisions for %title', ['%title' => $node->label()]);
     $header = array($this->t('Revision'), $this->t('Operations'));
     $revert_permission = ($account->hasPermission("revert {$type} revisions") || $account->hasPermission('revert all revisions') || $account->hasPermission('administer nodes')) && $node->access('update');
     $delete_permission = ($account->hasPermission("delete {$type} revisions") || $account->hasPermission('delete all revisions') || $account->hasPermission('administer nodes')) && $node->access('delete');
     $rows = array();
     $vids = $node_storage->revisionIds($node);
     $latest_revision = TRUE;
     foreach (array_reverse($vids) as $vid) {
         /** @var \Drupal\node\NodeInterface $revision */
         $revision = $node_storage->loadRevision($vid);
         // Only show revisions that are affected by the language that is being
         // displayed.
         if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
             $username = ['#theme' => 'username', '#account' => $revision->getRevisionAuthor()];
             // Use revision link to link to revisions that are not active.
             $date = $this->dateFormatter->format($revision->revision_timestamp->value, 'short');
             if ($vid != $node->getRevisionId()) {
                 $link = $this->l($date, new Url('entity.node.revision', ['node' => $node->id(), 'node_revision' => $vid]));
             } else {
                 $link = $node->link($date);
             }
             $row = [];
             $column = ['data' => ['#type' => 'inline_template', '#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}', '#context' => ['date' => $link, 'username' => $this->renderer->renderPlain($username), 'message' => ['#markup' => $revision->revision_log->value, '#allowed_tags' => Xss::getHtmlTagList()]]]];
             // @todo Simplify once https://www.drupal.org/node/2334319 lands.
             $this->renderer->addCacheableDependency($column['data'], $username);
             $row[] = $column;
             if ($latest_revision) {
                 $row[] = ['data' => ['#prefix' => '<em>', '#markup' => $this->t('Current revision'), '#suffix' => '</em>']];
                 foreach ($row as &$current) {
                     $current['class'] = ['revision-current'];
                 }
                 $latest_revision = FALSE;
             } else {
                 $links = [];
                 if ($revert_permission) {
                     $links['revert'] = ['title' => $this->t('Revert'), 'url' => $has_translations ? Url::fromRoute('node.revision_revert_translation_confirm', ['node' => $node->id(), 'node_revision' => $vid, 'langcode' => $langcode]) : Url::fromRoute('node.revision_revert_confirm', ['node' => $node->id(), 'node_revision' => $vid])];
                 }
                 if ($delete_permission) {
                     $links['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('node.revision_delete_confirm', ['node' => $node->id(), 'node_revision' => $vid])];
                 }
                 $row[] = ['data' => ['#type' => 'operations', '#links' => $links]];
             }
             $rows[] = $row;
         }
     }
     $build['node_revisions_table'] = array('#theme' => 'table', '#rows' => $rows, '#header' => $header, '#attached' => array('library' => array('node/drupal.node.admin')));
     return $build;
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:66,代码来源:NodeController.php

示例8: buildOptionsForm

 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     $date_formats = array();
     foreach ($this->dateFormatStorage->loadMultiple() as $machine_name => $value) {
         $date_formats[$machine_name] = $this->t('@name format: @date', array('@name' => $value->label(), '@date' => $this->dateFormatter->format(REQUEST_TIME, $machine_name)));
     }
     $form['date_format'] = array('#type' => 'select', '#title' => $this->t('Date format'), '#options' => $date_formats + array('custom' => $this->t('Custom'), 'raw time ago' => $this->t('Time ago'), 'time ago' => $this->t('Time ago (with "ago" appended)'), 'raw time hence' => $this->t('Time hence'), 'time hence' => $this->t('Time hence (with "hence" appended)'), 'raw time span' => $this->t('Time span (future dates have "-" prepended)'), 'inverse time span' => $this->t('Time span (past dates have "-" prepended)'), 'time span' => $this->t('Time span (with "ago/hence" appended)')), '#default_value' => isset($this->options['date_format']) ? $this->options['date_format'] : 'small');
     $form['custom_date_format'] = array('#type' => 'textfield', '#title' => $this->t('Custom date format'), '#description' => $this->t('If "Custom", see <a href="http://us.php.net/manual/en/function.date.php" target="_blank">the PHP docs</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.'), '#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '');
     // Setup #states for all possible date_formats on the custom_date_format form element.
     foreach (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') as $custom_date_possible) {
         $form['custom_date_format']['#states']['visible'][] = array(':input[name="options[date_format]"]' => array('value' => $custom_date_possible));
     }
     $form['timezone'] = array('#type' => 'select', '#title' => $this->t('Timezone'), '#description' => $this->t('Timezone to be used for date output.'), '#options' => array('' => $this->t('- Default site/user timezone -')) + system_time_zones(FALSE), '#default_value' => $this->options['timezone']);
     foreach (array_merge(array('custom'), array_keys($date_formats)) as $timezone_date_formats) {
         $form['timezone']['#states']['visible'][] = array(':input[name="options[date_format]"]' => array('value' => $timezone_date_formats));
     }
     parent::buildOptionsForm($form, $form_state);
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:21,代码来源:Date.php

示例9: opSimple

 /**
  * Override parent method, which deals with dates as integers.
  */
 protected function opSimple($field)
 {
     $origin = !empty($this->value['type']) && $this->value['type'] == 'offset' ? $this->requestStack->getCurrentRequest()->server->get('REQUEST_TIME') : 0;
     $value = intval(strtotime($this->value['value'], $origin));
     // Convert to ISO. UTC is used since dates are stored in UTC.
     $value = $this->query->getDateFormat("'" . $this->dateFormatter->format($value, 'custom', DATETIME_DATETIME_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE) . "'", $this->dateFormat, TRUE);
     // This is safe because we are manually scrubbing the value.
     $field = $this->query->getDateFormat($field, $this->dateFormat, TRUE);
     $this->query->addWhereExpression($this->options['group'], "{$field} {$this->operator} {$value}");
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:Date.php

示例10: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     /* @var \Drupal\commerce_order\Entity\Order $order */
     $order = $this->entity;
     $form = parent::form($form, $form_state);
     $form['#tree'] = TRUE;
     $form['#theme'] = 'commerce_order_edit_form';
     $form['#attached']['library'][] = 'commerce_order/form';
     // Changed must be sent to the client, for later overwrite error checking.
     $form['changed'] = ['#type' => 'hidden', '#default_value' => $order->getChangedTime()];
     $last_saved = $this->dateFormatter->format($order->getChangedTime(), 'short');
     $form['advanced'] = ['#type' => 'container', '#attributes' => ['class' => ['entity-meta']], '#weight' => 99];
     $form['meta'] = ['#attributes' => ['class' => ['entity-meta__header']], '#type' => 'container', '#group' => 'advanced', '#weight' => -100, 'state' => ['#type' => 'html_tag', '#tag' => 'h3', '#value' => $order->getState()->getLabel(), '#attributes' => ['class' => 'entity-meta__title'], '#access' => empty($form['store_id'])], 'date' => NULL, 'changed' => $this->fieldAsReadOnly($this->t('Last saved'), $last_saved)];
     $form['customer'] = ['#type' => 'details', '#title' => t('Customer information'), '#group' => 'advanced', '#open' => TRUE, '#attributes' => ['class' => ['order-form-author']], '#weight' => 91];
     if ($placed_time = $order->getPlacedTime()) {
         $date = $this->dateFormatter->format($placed_time, 'short');
         $form['meta']['date'] = $this->fieldAsReadOnly($this->t('Placed'), $date);
     }
     // Show the order's store only if there are multiple available.
     $store_query = $this->entityManager->getStorage('commerce_store')->getQuery();
     $store_count = $store_query->count()->execute();
     if ($store_count > 1) {
         $store_link = $order->getStore()->toLink()->toString();
         $form['meta']['store'] = $this->fieldAsReadOnly($this->t('Store'), $store_link);
     }
     // Move uid/mail widgets to the sidebar, or provide read-only alternatives.
     if (isset($form['uid'])) {
         $form['uid']['#group'] = 'customer';
     } else {
         $user_link = $order->getOwner()->toLink()->toString();
         $form['customer']['uid'] = $this->fieldAsReadOnly($this->t('Customer'), $user_link);
     }
     if (isset($form['mail'])) {
         $form['mail']['#group'] = 'customer';
     } else {
         $form['customer']['mail'] = $this->fieldAsReadOnly($this->t('Contact email'), $order->getEmail());
     }
     // All additional customer information should come after uid/mail.
     $form['customer']['ip_address'] = $this->fieldAsReadOnly($this->t('IP address'), $order->getIpAddress());
     return $form;
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:44,代码来源:OrderForm.php

示例11: eventDetails

 /**
  * Displays details about a specific database log message.
  *
  * @param int $event_id
  *   Unique ID of the database log message.
  *
  * @return array
  *   If the ID is located in the Database Logging table, a build array in the
  *   format expected by drupal_render();
  *
  */
 public function eventDetails($event_id)
 {
     $build = array();
     if ($dblog = $this->database->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', array(':id' => $event_id))->fetchObject()) {
         $severity = RfcLogLevel::getLevels();
         $message = $this->formatMessage($dblog);
         $username = array('#theme' => 'username', '#account' => $dblog->uid ? $this->userStorage->load($dblog->uid) : User::getAnonymousUser());
         $rows = array(array(array('data' => $this->t('Type'), 'header' => TRUE), $this->t($dblog->type)), array(array('data' => $this->t('Date'), 'header' => TRUE), $this->dateFormatter->format($dblog->timestamp, 'long')), array(array('data' => $this->t('User'), 'header' => TRUE), array('data' => $username)), array(array('data' => $this->t('Location'), 'header' => TRUE), $this->l($dblog->location, $dblog->location ? Url::fromUri($dblog->location) : Url::fromRoute('<none>'))), array(array('data' => $this->t('Referrer'), 'header' => TRUE), $this->l($dblog->referer, $dblog->referer ? Url::fromUri($dblog->referer) : Url::fromRoute('<none>'))), array(array('data' => $this->t('Message'), 'header' => TRUE), $message), array(array('data' => $this->t('Severity'), 'header' => TRUE), $severity[$dblog->severity]), array(array('data' => $this->t('Hostname'), 'header' => TRUE), $dblog->hostname), array(array('data' => $this->t('Operations'), 'header' => TRUE), array('data' => array('#markup' => $dblog->link))));
         $build['dblog_table'] = array('#type' => 'table', '#rows' => $rows, '#attributes' => array('class' => array('dblog-event')), '#attached' => array('library' => array('dblog/drupal.dblog')));
     }
     return $build;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:23,代码来源:DbLogController.php

示例12: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // The revision timestamp will be updated when the revision is saved. Keep
     // the original one for the confirmation message.
     $original_revision_timestamp = $this->revision->getRevisionCreationTime();
     $this->revision = $this->prepareRevertedRevision($this->revision, $form_state);
     $this->revision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
     $this->revision->save();
     $this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
     drupal_set_message(t('@type %title has been reverted to the revision from %revision-date.', ['@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)]));
     $form_state->setRedirect('entity.node.version_history', array('node' => $this->revision->id()));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:15,代码来源:NodeRevisionRevertForm.php

示例13: buildRow

 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\node\NodeInterface $entity */
     $mark = array('#theme' => 'mark', '#mark_type' => node_mark($entity->id(), $entity->getChangedTime()));
     $langcode = $entity->language()->getId();
     $uri = $entity->urlInfo();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
     $uri->setOptions($options);
     $row['title']['data'] = array('#type' => 'link', '#title' => $entity->label(), '#suffix' => ' ' . drupal_render($mark), '#url' => $uri);
     $row['type'] = node_get_type_label($entity);
     $row['author']['data'] = array('#theme' => 'username', '#account' => $entity->getOwner());
     $row['status'] = $entity->isPublished() ? $this->t('published') : $this->t('not published');
     $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
     $language_manager = \Drupal::languageManager();
     if ($language_manager->isMultilingual()) {
         $row['language_name'] = $language_manager->getLanguageName($langcode);
     }
     $row['operations']['data'] = $this->buildOperations($entity);
     return $row + parent::buildRow($entity);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:24,代码来源:NodeListBuilder.php

示例14: createUser

 private function createUser($username, $password, $roles, $email = null, $status = null)
 {
     $password = $password ?: $this->generatePassword();
     $user = User::create(['name' => $username, 'mail' => $email ?: $username . '@example.com', 'pass' => $password, 'status' => $status, 'roles' => $roles, 'created' => REQUEST_TIME]);
     $result = [];
     try {
         $user->save();
         $result['success'] = ['user-id' => $user->id(), 'username' => $user->getUsername(), 'password' => $password, 'email' => $user->getEmail(), 'roles' => implode(', ', $roles), 'created' => $this->dateFormatter->format($user->getCreatedTime(), 'custom', 'Y-m-d h:i:s'), 'status' => $status];
     } catch (\Exception $e) {
         $result['error'] = ['vid' => $user->id(), 'name' => $user->get('name'), 'error' => 'Error: ' . get_class($e) . ', code: ' . $e->getCode() . ', message: ' . $e->getMessage()];
     }
     return $result;
 }
开发者ID:ranqiangjun,项目名称:DrupalConsole,代码行数:13,代码来源:CreateCommand.php

示例15: buildForm

 /**
  * Form constructor for the comment overview administration form.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param string $type
  *   The type of the overview form ('approval' or 'new').
  *
  * @return array
  *   The form structure.
  */
 public function buildForm(array $form, FormStateInterface $form_state, $type = 'new')
 {
     // Build an 'Update options' form.
     $form['options'] = array('#type' => 'details', '#title' => $this->t('Update options'), '#open' => TRUE, '#attributes' => array('class' => array('container-inline')));
     if ($type == 'approval') {
         $options['publish'] = $this->t('Publish the selected comments');
     } else {
         $options['unpublish'] = $this->t('Unpublish the selected comments');
     }
     $options['delete'] = $this->t('Delete the selected comments');
     $form['options']['operation'] = array('#type' => 'select', '#title' => $this->t('Action'), '#title_display' => 'invisible', '#options' => $options, '#default_value' => 'publish');
     $form['options']['submit'] = array('#type' => 'submit', '#value' => $this->t('Update'));
     // Load the comments that need to be displayed.
     $status = $type == 'approval' ? CommentInterface::NOT_PUBLISHED : CommentInterface::PUBLISHED;
     $header = array('subject' => array('data' => $this->t('Subject'), 'specifier' => 'subject'), 'author' => array('data' => $this->t('Author'), 'specifier' => 'name', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), 'posted_in' => array('data' => $this->t('Posted in'), 'class' => array(RESPONSIVE_PRIORITY_LOW)), 'changed' => array('data' => $this->t('Updated'), 'specifier' => 'changed', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)), 'operations' => $this->t('Operations'));
     $cids = $this->commentStorage->getQuery()->condition('status', $status)->tableSort($header)->pager(50)->execute();
     /** @var $comments \Drupal\comment\CommentInterface[] */
     $comments = $this->commentStorage->loadMultiple($cids);
     // Build a table listing the appropriate comments.
     $options = array();
     $destination = $this->getDestinationArray();
     $commented_entity_ids = array();
     $commented_entities = array();
     foreach ($comments as $comment) {
         $commented_entity_ids[$comment->getCommentedEntityTypeId()][] = $comment->getCommentedEntityId();
     }
     foreach ($commented_entity_ids as $entity_type => $ids) {
         $commented_entities[$entity_type] = $this->entityManager->getStorage($entity_type)->loadMultiple($ids);
     }
     foreach ($comments as $comment) {
         /** @var $commented_entity \Drupal\Core\Entity\EntityInterface */
         $commented_entity = $commented_entities[$comment->getCommentedEntityTypeId()][$comment->getCommentedEntityId()];
         $comment_permalink = $comment->permalink();
         if ($comment->hasField('comment_body') && ($body = $comment->get('comment_body')->value)) {
             $attributes = $comment_permalink->getOption('attributes') ?: array();
             $attributes += array('title' => Unicode::truncate($body, 128));
             $comment_permalink->setOption('attributes', $attributes);
         }
         $options[$comment->id()] = array('title' => array('data' => array('#title' => $comment->getSubject() ?: $comment->id())), 'subject' => array('data' => array('#type' => 'link', '#title' => $comment->getSubject(), '#url' => $comment_permalink)), 'author' => array('data' => array('#theme' => 'username', '#account' => $comment->getOwner())), 'posted_in' => array('data' => array('#type' => 'link', '#title' => $commented_entity->label(), '#access' => $commented_entity->access('view'), '#url' => $commented_entity->urlInfo())), 'changed' => $this->dateFormatter->format($comment->getChangedTimeAcrossTranslations(), 'short'));
         $comment_uri_options = $comment->urlInfo()->getOptions() + ['query' => $destination];
         $links = array();
         $links['edit'] = array('title' => $this->t('Edit'), 'url' => $comment->urlInfo('edit-form', $comment_uri_options));
         if ($this->moduleHandler->moduleExists('content_translation') && $this->moduleHandler->invoke('content_translation', 'translate_access', array($comment))->isAllowed()) {
             $links['translate'] = array('title' => $this->t('Translate'), 'url' => $comment->urlInfo('drupal:content-translation-overview', $comment_uri_options));
         }
         $options[$comment->id()]['operations']['data'] = array('#type' => 'operations', '#links' => $links);
     }
     $form['comments'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options, '#empty' => $this->t('No comments available.'));
     $form['pager'] = array('#type' => 'pager');
     return $form;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:64,代码来源:CommentAdminOverview.php


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