本文整理汇总了PHP中Drupal\Core\Datetime\DateFormatter::format方法的典型用法代码示例。如果您正苦于以下问题:PHP DateFormatter::format方法的具体用法?PHP DateFormatter::format怎么用?PHP DateFormatter::format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Datetime\DateFormatter
的用法示例。
在下文中一共展示了DateFormatter::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\commerce_order\Entity\Order */
$orderType = OrderType::load($entity->bundle());
$row = ['order_id' => $entity->id(), 'type' => $orderType->label(), 'customer' => ['data' => ['#theme' => 'username', '#account' => $entity->getOwner()]], 'state' => $entity->getState()->getLabel(), 'created' => $this->dateFormatter->format($entity->getCreatedTime(), 'short')];
return $row + parent::buildRow($entity);
}
示例2: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row = array();
$row['label']['data'] = array('#type' => 'link', '#title' => SafeMarkup::checkPlain($entity->label()), '#url' => $entity->urlInfo());
$row['type'] = SafeMarkup::checkPlain($entity->get('type')->entity->label());
$row['changed'] = $this->dateFormatter->format($entity->get('changed')->value, 'short');
return $row + parent::buildRow($entity);
}
示例3: getQuestion
/**
* {@inheritdoc}
*/
public function getQuestion()
{
if ($this->entityRevision instanceof TimestampedRevisionInterface) {
return t('Are you sure you want to delete the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->entityRevision->getRevisionCreationTime())]);
} else {
return t('Are you sure you want to delete to the revision');
}
}
示例4: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
if ($entity->isLocked()) {
$row['id'] = $this->t('@entity_id (locked)', array('@entity_id' => $entity->id()));
} else {
$row['id'] = $entity->id();
}
$row['label'] = $this->getLabel($entity);
$row['pattern'] = $this->dateFormatter->format(REQUEST_TIME, $entity->id());
return $row + parent::buildRow($entity);
}
示例5: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$uri = $entity->urlInfo();
$options = $uri->getOptions();
$uri->setOptions($options);
$row['title']['data'] = ['#type' => 'link', '#title' => $entity->label(), '#url' => $uri];
$row['type'] = SafeMarkup::checkPlain($entity->getType()->label());
$row['author']['data'] = ['#theme' => 'username', '#account' => $entity->getOwner()];
$row['status'] = $entity->isActive() ? $this->t('active') : $this->t('not active');
$row['imported'] = $this->dateFormatter->format($entity->getImportedTime(), 'short');
$row['operations']['data'] = $this->buildOperations($entity);
return $row + parent::buildRow($entity);
}
示例6: index
/**
* Index.
*
* @return array
* Render array with all the entries.
*/
public function index()
{
$output = ['#cache' => ['max-age' => 0]];
// This is going to be reused at two places: once for the TableSortExtender,
// and once for the table header itself.
$header = [['data' => $this->t('Created'), 'field' => 'p.created'], ['data' => $this->t('Changed'), 'field' => 'p.changed'], ['data' => $this->t('Name'), 'field' => 'p.name'], ['data' => $this->t('Phone'), 'field' => 'p.phone'], ['data' => $this->t('Operations'), 'colspan' => '2']];
$query = $this->connection->select('phonebook', 'p')->extend('Drupal\\Core\\Database\\Query\\TableSortExtender')->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
$query->fields('p');
$result = $query->orderByHeader($header)->limit(25)->execute();
$output['table'] = ['#type' => 'table', '#header' => $header, '#empty' => $this->t('No entries found.')];
foreach ($result as $row) {
$output['table'][] = [['data' => ['#markup' => $this->date_formatter->format($row->created)]], ['data' => ['#markup' => $this->date_formatter->formatTimeDiffSince($row->changed)]], ['data' => ['#markup' => $row->name]], ['data' => ['#markup' => $row->phone]], ['data' => ['#markup' => $this->l($this->t('edit'), new Url('d8phonebook.edit', ['phonebook' => $row->pbid]))]], ['data' => ['#markup' => $this->l($this->t('delete'), new Url('d8phonebook.delete', ['phonebook' => $row->pbid], ['query' => ['token' => $this->csrf_token_generator->get('phonebook/' . $row->pbid . '/delete')]]))]]];
}
$output['pager'] = array('#type' => 'pager');
return $output;
}
示例7: listAction
/**
* Generates the list page.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return array
*/
public function listAction(Request $request)
{
$limit = $request->get('limit', 10);
$this->profiler->disable();
$ip = $request->query->get('ip');
$method = $request->query->get('method');
$url = $request->query->get('url');
$profiles = $this->profiler->find($ip, $url, $limit, $method, '', '');
$rows = [];
if (count($profiles)) {
foreach ($profiles as $profile) {
$row = [];
$row[] = $this->l($profile['token'], new Url('webprofiler.dashboard', ['profile' => $profile['token']]));
$row[] = $profile['ip'];
$row[] = $profile['method'];
$row[] = $profile['url'];
$row[] = $this->date->format($profile['time']);
$rows[] = $row;
}
} else {
$rows[] = [['data' => $this->t('No profiles found'), 'colspan' => 6]];
}
$build = [];
$storage_id = $this->config('webprofiler.config')->get('storage');
$storage = $this->storageManager->getStorage($storage_id);
$build['resume'] = ['#type' => 'inline_template', '#template' => '<p>{{ message }}</p>', '#context' => ['message' => $this->t('Profiles stored with %storage service.', ['%storage' => $storage['title']])]];
$build['filters'] = $this->formBuilder()->getForm('Drupal\\webprofiler\\Form\\ProfilesFilterForm');
$build['table'] = ['#type' => 'table', '#rows' => $rows, '#header' => [$this->t('Token'), ['data' => $this->t('Ip'), 'class' => [RESPONSIVE_PRIORITY_LOW]], ['data' => $this->t('Method'), 'class' => [RESPONSIVE_PRIORITY_LOW]], $this->t('Url'), ['data' => $this->t('Time'), 'class' => [RESPONSIVE_PRIORITY_MEDIUM]]], '#sticky' => TRUE];
return $build;
}
示例8: preRender
/**
* Implements form #pre_render callback.
*
* @throws \InvalidArgumentException
*/
public function preRender(array $element)
{
if (!isset($element['#payment_statuses']) || !is_array($element['#payment_statuses'])) {
throw new \InvalidArgumentException('#payment_statuses must be an array of \\Drupal\\payment\\Plugin\\Payment\\Status\\PaymentStatusInterface instances.');
}
$element['table'] = array('#empty' => $this->t('There are no statuses.'), '#header' => array($this->t('Status'), $this->t('Date')), '#type' => 'table');
/** @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusInterface $status */
foreach ($element['#payment_statuses'] as $delta => $payment_status) {
if (!$payment_status instanceof PaymentStatusInterface) {
$type = is_object($payment_status) ? get_class($payment_status) : gettype($payment_status);
throw new \InvalidArgumentException(sprintf('#payment_statuses must be an array of \\Drupal\\payment\\Plugin\\Payment\\Status\\PaymentStatusInterface instances, but the array contained %s.', $type));
}
$definition = $payment_status->getPluginDefinition();
$element['table']['status_' . $delta] = array('#attributes' => array('class' => array('payment-status-plugin-' . $payment_status->getPluginId())), 'label' => array('#attributes' => array('class' => array('payment-status-label')), '#markup' => $definition['label']), 'created' => array('#attributes' => array('class' => array('payment-line-item-quantity')), '#markup' => $this->dateFormatter->format($payment_status->getCreated())));
}
return $element;
}
示例9: buildOptionsForm
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);
}
示例10: 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}");
}
示例11: 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()];
$username = array('#theme' => 'username', '#account' => $comment->getOwner());
$body = '';
if (!empty($comment->comment_body->value)) {
$body = $comment->comment_body->value;
}
$comment_permalink = $comment->permalink();
$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' => drupal_render($username), '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->getChangedTime(), 'short'));
$comment_uri_options = $comment->urlInfo()->getOptions();
$links = array();
$links['edit'] = array('title' => $this->t('Edit'), 'url' => Url::fromRoute('entity.comment.edit_form', ['comment' => $comment->id()], $comment_uri_options + ['query' => $destination]));
if ($this->moduleHandler->moduleExists('content_translation') && $this->moduleHandler->invoke('content_translation', 'translate_access', array($comment))->isAllowed()) {
$links['translate'] = array('title' => $this->t('Translate'), 'url' => Url::fromRoute('entity.comment.content_translation_overview', ['comment' => $comment->id()], $comment_uri_options + ['query' => $destination]));
}
$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;
}
示例12: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state)
{
$time = new DrupalDateTime();
$format_types = $this->dateStorage->loadMultiple();
foreach ($format_types as $type => $type_info) {
$format = $this->dateFormatter->format($time->format('U'), $type);
$options[$type] = $type_info->label() . ' (' . $format . ')';
}
$elements['format_type'] = array('#type' => 'select', '#title' => t('Date format'), '#description' => t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."), '#options' => $options, '#default_value' => $this->getSetting('format_type'));
return $elements;
}
示例13: 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()));
}
示例14: 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()->id;
$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)) + $uri->toRenderArray();
$row['type'] = String::checkPlain(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);
}
示例15: 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.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = :id', array(':id' => $event_id))->fetchObject()) {
$severity = watchdog_severity_levels();
$message = $this->formatMessage($dblog);
$username = array('#theme' => 'username', '#account' => user_load($dblog->uid));
$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), l($dblog->location, $dblog->location)), array(array('data' => $this->t('Referrer'), 'header' => TRUE), l($dblog->referer, $dblog->referer)), 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), String::checkPlain($dblog->hostname)), array(array('data' => $this->t('Operations'), 'header' => TRUE), $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;
}