/**
  * {@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);
 }
 /**
  * {@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);
 }
 /**
  * {@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');
     }
 }
 /**
  * {@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);
 }
Beispiel #5
0
 /**
  * {@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);
 }
Beispiel #6
0
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 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);
 }
Beispiel #10
0
 /**
  * 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}");
 }
Beispiel #11
0
 /**
  * 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;
 }
 /**
  * {@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;
 }
 /**
  * {@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()));
 }
 /**
  * {@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);
 }
 /**
  * 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;
 }
Beispiel #16
0
 /**
  * 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), SafeMarkup::checkPlain($dblog->hostname)), array(array('data' => $this->t('Operations'), 'header' => TRUE), SafeMarkup::checkAdminXss($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;
 }
  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    /** @var \Drupal\profile\ProfileInterface $entity */
    $mark = [
      '#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]) ? ['language' => $languages[$langcode]] : []);
    $uri->setOptions($options);
    $row['label']['data'] = [
        '#type' => 'link',
        '#title' => $entity->label(),
        '#suffix' => ' ' . drupal_render($mark),
      ] + $uri->toRenderArray();
    $row['type'] = $entity->getType()->id();
    $row['owner']['data'] = [
      '#theme' => 'username',
      '#account' => $entity->getOwner(),
    ];
    $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('not active');
    $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
    $language_manager = \Drupal::languageManager();
    if ($language_manager->isMultilingual()) {
      $row['language_name'] = $language_manager->getLanguageName($langcode);
    }

    $route_params = ['user' => $entity->getOwnerId(), 'type' => $entity->bundle(), 'profile' => $entity->id()];
    $links['edit'] = [
      'title' => t('Edit'),
      'route_name' => 'entity.profile.edit_form',
      'route_parameters' => $route_params,
    ];
    $links['delete'] = [
      'title' => t('Delete'),
      'route_name' => 'entity.profile.delete_form',
      'route_parameters' => $route_params,
    ];

    $row[] = [
      'data' => [
        '#type' => 'operations',
        '#links' => $links,
      ],
    ];

    return $row + parent::buildRow($entity);
  }
Beispiel #18
0
 /**
  * Build the datebox information for the current day.
  *
  * @todo expand documentation
  * If a day has no events, the empty day theme info is added to the return
  * array.
  *
  * @return array
  *   An array with information on the current day for use in a datebox.
  */
 public function calendarBuildDay()
 {
     $current_day_date = $this->currentDay->format(DATETIME_DATE_STORAGE_FORMAT);
     $selected = FALSE;
     $max_events = !empty($this->styleInfo->getMaxItems()) ? $this->styleInfo->getMaxItems() : 0;
     $ids = [];
     $inner = [];
     $all_day = [];
     $empty = '';
     $link = '';
     $count = 0;
     foreach ($this->items as $date => $day) {
         if ($date == $current_day_date) {
             $count = 0;
             $selected = TRUE;
             ksort($day);
             foreach ($day as $time => $hour) {
                 /** @var $item \Drupal\calendar\CalendarEvent */
                 foreach ($hour as $key => $item) {
                     $count++;
                     $ids[$item->getType()] = $item;
                     if (empty($this->styleInfo->isMini()) && ($max_events == CALENDAR_SHOW_ALL || $count <= $max_events || $count > 0 && $max_events == CALENDAR_HIDE_ALL)) {
                         if ($item->isAllDay()) {
                             $item->setIsMultiDay(TRUE);
                             $all_day[] = $item;
                         } else {
                             $this->dateFormatter->format($item->getStartDate()->getTimestamp(), 'custom', 'H:i:s');
                             $inner[$key][] = $item;
                         }
                     }
                 }
             }
         }
     }
     ksort($inner);
     if (empty($inner) && empty($all_day)) {
         $empty = ['#theme' => 'calendar_empty_day', '#curday' => $current_day_date, '#view' => $this->view];
     }
     // We have hidden events on this day, use the theme('calendar_multiple_') to show a link.
     if ($max_events != CALENDAR_SHOW_ALL && $count > 0 && $count > $max_events && $this->dateInfo->getCalendarType() != 'day' && !$this->styleInfo->isMini()) {
         if ($this->styleInfo->getMaxItemsStyle() == 'hide' || $max_events == CALENDAR_HIDE_ALL) {
             $all_day = [];
             $inner = [];
         }
         $link = ['#theme' => 'calendar_' . $this->dateInfo->getCalendarType() . '_multiple_entity', '#curday' => $current_day_date, '#count' => $count, '#view' => $this->view, '#ids' => $ids];
     }
     $content = ['#date' => $current_day_date, 'datebox' => ['#theme' => 'calendar_datebox', '#date' => $current_day_date, '#view' => $this->view, '#items' => $this->items, '#selected' => $selected], '#empty' => $empty, '#link' => $link, 'all_day' => $all_day, 'items' => $inner];
     return $content;
 }
Beispiel #19
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     $date_format = $this->getSetting('date_format');
     $custom_date_format = '';
     $timezone = $this->getSetting('timezone') ?: NULL;
     $langcode = NULL;
     // If an RFC2822 date format is requested, then the month and day have to
     // be in English. @see http://www.faqs.org/rfcs/rfc2822.html
     if ($date_format === 'custom' && ($custom_date_format = $this->getSetting('custom_date_format')) === 'r') {
         $langcode = 'en';
     }
     foreach ($items as $delta => $item) {
         $elements[$delta] = ['#cache' => ['contexts' => ['timezone']], '#markup' => $this->dateFormatter->format($item->value, $date_format, $custom_date_format, $timezone, $langcode)];
     }
     return $elements;
 }
 /**
  * Returns a formatted date based on the passed timestamp and gap.
  *
  * This function assumes that gaps less than one day will be displayed in a
  * search context in which a larger containing gap including a day is already
  * displayed. So, HOUR, MINUTE, and SECOND gaps only display time information,
  * without date.
  *
  * @param int $timestamp
  *   An integer containing the Unix timestamp.
  * @param string $gap
  *   A string containing the gap, see FACETS_DATE_* constants for valid
  *   values, defaults to YEAR.
  *
  * @return string
  *   A gap-appropriate display date used in the facet link.
  */
 public function formatTimestamp($timestamp, $gap = self::FACETS_DATE_YEAR)
 {
     switch ($gap) {
         case static::FACETS_DATE_MONTH:
             return $this->dateFormatter->format($timestamp, 'custom', 'F Y', 'UTC');
         case static::FACETS_DATE_DAY:
             return $this->dateFormatter->format($timestamp, 'custom', 'F j, Y', 'UTC');
         case static::FACETS_DATE_HOUR:
             return $this->dateFormatter->format($timestamp, 'custom', 'g A', 'UTC');
         case static::FACETS_DATE_MINUTE:
             return $this->dateFormatter->format($timestamp, 'custom', 'g:i A', 'UTC');
         case static::FACETS_DATE_SECOND:
             return $this->dateFormatter->format($timestamp, 'custom', 'g:i:s A', 'UTC');
         default:
             return $this->dateFormatter->format($timestamp, 'custom', 'Y', 'UTC');
     }
 }
 /**
  * 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();
     $node_storage = $this->entityManager()->getStorage('node');
     $type = $node->getType();
     $build = array();
     $build['#title'] = $this->t('Revisions for %title', array('%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);
     foreach (array_reverse($vids) as $vid) {
         $revision = $node_storage->loadRevision($vid);
         $username = ['#theme' => 'username', '#account' => $revision->uid->entity];
         // 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' => Xss::filter($revision->revision_log->value)]]];
         // @todo Simplify once https://www.drupal.org/node/2334319 lands.
         $this->renderer->addCacheableDependency($column['data'], $username);
         $row[] = $column;
         if ($vid == $node->getRevisionId()) {
             $row[0]['class'] = ['revision-current'];
             $row[] = ['data' => SafeMarkup::placeholder($this->t('current revision')), 'class' => ['revision-current']];
         } else {
             $links = [];
             if ($revert_permission) {
                 $links['revert'] = ['title' => $this->t('Revert'), 'url' => 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;
 }
Beispiel #22
0
 /**
  * Returns the user password reset page.
  *
  * @param int $uid
  *   UID of user requesting reset.
  * @param int $timestamp
  *   The current timestamp.
  * @param string $hash
  *   Login link hash.
  *
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  *   The form structure or a redirect response.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  *   If the login link is for a blocked user or invalid user ID.
  */
 public function resetPass($uid, $timestamp, $hash)
 {
     $account = $this->currentUser();
     $config = $this->config('user.settings');
     // When processing the one-time login link, we have to make sure that a user
     // isn't already logged in.
     if ($account->isAuthenticated()) {
         // The current user is already logged in.
         if ($account->id() == $uid) {
             drupal_set_message($this->t('You are logged in as %user. <a href="!user_edit">Change your password.</a>', array('%user' => $account->getUsername(), '!user_edit' => $this->url('user.edit', array('user' => $account->id())))));
         } else {
             if ($reset_link_user = $this->userStorage->load($uid)) {
                 drupal_set_message($this->t('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please <a href="!logout">logout</a> and try using the link again.', array('%other_user' => $account->getUsername(), '%resetting_user' => $reset_link_user->getUsername(), '!logout' => $this->url('user.logout'))));
             } else {
                 // Invalid one-time link specifies an unknown user.
                 drupal_set_message($this->t('The one-time login link you clicked is invalid.'));
             }
         }
         return $this->redirect('<front>');
     } else {
         // The current user is not logged in, so check the parameters.
         // Time out, in seconds, until login URL expires.
         $timeout = $config->get('password_reset_timeout');
         $current = REQUEST_TIME;
         /* @var \Drupal\user\UserInterface $user */
         $user = $this->userStorage->load($uid);
         // Verify that the user exists and is active.
         if ($user && $user->isActive()) {
             // No time out for first time login.
             if ($user->getLastLoginTime() && $current - $timestamp > $timeout) {
                 drupal_set_message($this->t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'));
                 return $this->redirect('user.pass');
             } elseif ($user->isAuthenticated() && $timestamp >= $user->getLastLoginTime() && $timestamp <= $current && $hash === user_pass_rehash($user->getPassword(), $timestamp, $user->getLastLoginTime())) {
                 $expiration_date = $user->getLastLoginTime() ? $this->dateFormatter->format($timestamp + $timeout) : NULL;
                 return $this->formBuilder()->getForm('Drupal\\user\\Form\\UserPasswordResetForm', $user, $expiration_date, $timestamp, $hash);
             } else {
                 drupal_set_message($this->t('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.'));
                 return $this->redirect('user.pass');
             }
         }
     }
     // 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();
 }
 /**
  * {@inheritdnoc}
  */
 public function buildRow(EntityInterface $payment)
 {
     /** @var \Drupal\payment\Entity\PaymentInterface $payment */
     $row['data']['updated'] = $this->dateFormatter->format($payment->getChangedTime());
     $status_definition = $payment->getPaymentStatus()->getPluginDefinition();
     $row['data']['status'] = $status_definition['label'];
     /** @var \Drupal\currency\Entity\CurrencyInterface $currency */
     $currency = $this->currencyStorage->load($payment->getCurrencyCode());
     if (!$currency) {
         $currency = $this->currencyStorage->load('XXX');
     }
     $row['data']['amount'] = $currency->formatAmount($payment->getAmount());
     $row['data']['payment_method'] = $payment->getPaymentMethod() ? $payment->getPaymentMethod()->getPluginDefinition()['label'] : $this->t('Unavailable');
     $row['data']['owner']['data'] = array('#theme' => 'username', '#account' => $payment->getOwner());
     $operations = $this->buildOperations($payment);
     $row['data']['operations']['data'] = $operations;
     return $row;
 }
  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    /* @var $entity \Drupal\commerce_payment\Entity\PaymentInfo */
    $paymentInfoType = PaymentInfoType::load($entity->bundle());

    $row = array(
      'information_id' => $entity->id(),
      'payment_method' => $paymentInfoType->label(),
      'owner' => array(
        'data' => array(
          '#theme' => 'username',
          '#account' => $entity->getOwner(),
        ),
      ),
      'status' => $entity->getStatus(),
      'created' => $this->dateFormatter->format($entity->getCreatedTime(), 'short'),
      'changed' => $this->dateFormatter->format($entity->getChangedTime(), 'short'),
    );
    return $row + parent::buildRow($entity);
  }
 /**
  * {@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.
     $this->entityRevision->setNewRevision();
     $this->entityRevision->isDefaultRevision(TRUE);
     if ($this->entityRevision instanceof EntityRevisionLogInterface) {
         if ($this->entityRevision instanceof TimestampedRevisionInterface) {
             $original_revision_timestamp = $this->entityRevision->getRevisionCreationTime();
             $this->entityRevision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
         } else {
             $this->entityRevision->revision_log = t('Copy of the revision');
         }
     }
     $this->entityRevision->save();
     $this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->entityRevision->bundle(), '%title' => $this->entityRevision->label(), '%revision' => $this->entityRevision->getRevisionId()]);
     drupal_set_message(t('@type %title has been reverted to the revision', ['@type' => $this->entityRevision->{$this->entityRevision->getEntityType()->getKey('bundle')}->entity->label(), '%title' => $this->entityRevision->label()]));
     $form_state->setRedirectUrl($this->entityRevision->urlInfo('version-history'));
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\profile\Entity\ProfileInterface $entity */
     $langcode = $entity->language()->getId();
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? ['language' => $languages[$langcode]] : [];
     $uri->setOptions($options);
     $row['label'] = $entity->link();
     $row['type'] = $entity->getType();
     $row['owner']['data'] = ['#theme' => 'username', '#account' => $entity->getOwner()];
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('not active');
     $row['is_default'] = $entity->isDefault() ? $this->t('default') : $this->t('not default');
     $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
     $language_manager = \Drupal::languageManager();
     if ($language_manager->isMultilingual()) {
         $row['language_name'] = $language_manager->getLanguageName($langcode);
     }
     return $row + parent::buildRow($entity);
 }
 /**
  * Builds the payment view.
  *
  * @param mixed[] $element
  *   The root element.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *
  * @return array
  *   A render array.
  */
 protected function buildPaymentView(array $element, FormStateInterface $form_state)
 {
     $payment_id = $element['#default_value'] ?: $element['#available_payment_id'];
     /** @var \Drupal\payment\Entity\PaymentInterface|null $payment */
     $payment = $payment_id ? $this->paymentStorage->load($payment_id) : NULL;
     $build = [];
     if ($payment) {
         $currency = $payment->getCurrency();
         $status = $payment->getPaymentStatus();
         $status_definition = $status->getPluginDefinition();
         $build = array('#empty' => $this->t('There are no line items.'), '#header' => array($this->t('Amount'), $this->t('Status'), $this->t('Last updated')), '#type' => 'table');
         $build[0]['amount'] = array('#markup' => $currency->formatAmount($payment->getAmount()));
         $build[0]['status'] = array('#markup' => $status_definition['label']);
         $build[0]['updated'] = array('#markup' => $this->dateFormatter->format($status->getCreated()));
         if ($payment->access('view')) {
             $build['#header'][] = $this->t('Operations');
             $build[0]['view'] = array('#markup' => $this->t('<a href="@url" target="_blank">View payment details</a> (opens in a new window)', array('@url' => $payment->url())));
         }
     }
     return $build;
 }
Beispiel #28
0
 /**
  * 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();
     $node_storage = $this->entityManager()->getStorage('node');
     $type = $node->getType();
     $build = array();
     $build['#title'] = $this->t('Revisions for %title', array('%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);
     foreach (array_reverse($vids) as $vid) {
         if ($revision = $node_storage->loadRevision($vid)) {
             $row = array();
             $revision_author = $revision->uid->entity;
             if ($vid == $node->getRevisionId()) {
                 $username = array('#theme' => 'username', '#account' => $revision_author);
                 $row[] = array('data' => $this->t('!date by !username', array('!date' => $node->link($this->dateFormatter->format($revision->revision_timestamp->value, 'short')), '!username' => drupal_render($username))) . ($revision->revision_log->value != '' ? '<p class="revision-log">' . Xss::filter($revision->revision_log->value) . '</p>' : ''), 'class' => array('revision-current'));
                 $row[] = array('data' => SafeMarkup::placeholder($this->t('current revision')), 'class' => array('revision-current'));
             } else {
                 $username = array('#theme' => 'username', '#account' => $revision_author);
                 $row[] = $this->t('!date by !username', array('!date' => $this->l($this->dateFormatter->format($revision->revision_timestamp->value, 'short'), new Url('entity.node.revision', array('node' => $node->id(), 'node_revision' => $vid))), '!username' => drupal_render($username))) . ($revision->revision_log->value != '' ? '<p class="revision-log">' . Xss::filter($revision->revision_log->value) . '</p>' : '');
                 if ($revert_permission) {
                     $links['revert'] = array('title' => $this->t('Revert'), 'url' => Url::fromRoute('node.revision_revert_confirm', ['node' => $node->id(), 'node_revision' => $vid]));
                 }
                 if ($delete_permission) {
                     $links['delete'] = array('title' => $this->t('Delete'), 'url' => Url::fromRoute('node.revision_delete_confirm', ['node' => $node->id(), 'node_revision' => $vid]));
                 }
                 $row[] = array('data' => array('#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;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['pattern'] = $this->dateFormatter->format(REQUEST_TIME, $entity->id());
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function getQuestion()
 {
     return t('Are you sure you want to remove the format %name : %format?', array('%name' => $this->entity->label(), '%format' => $this->dateFormatter->format(REQUEST_TIME, $this->entity->id())));
 }