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


PHP Unicode::truncate方法代码示例

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


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

示例1: listItems

 /**
  * Lists the feed items belonging to a feed.
  */
 public function listItems(FeedInterface $feeds_feed, Request $request)
 {
     $processor = $feeds_feed->getType()->getProcessor();
     $header = ['title' => $this->t('Label'), 'imported' => $this->t('Imported'), 'guid' => ['data' => $this->t('GUID'), 'class' => [RESPONSIVE_PRIORITY_LOW]], 'url' => ['data' => $this->t('URL'), 'class' => [RESPONSIVE_PRIORITY_LOW]]];
     $build = [];
     $build['table'] = ['#type' => 'table', '#header' => $header, '#rows' => [], '#empty' => $this->t('There are no items yet.')];
     // @todo Allow processors to create their own entity listings.
     if (!$processor instanceof EntityProcessorInterface) {
         return $build;
     }
     $entity_ids = \Drupal::entityQuery($processor->entityType())->condition('feeds_item.target_id', $feeds_feed->id())->pager(50)->sort('feeds_item.imported', 'DESC')->execute();
     $storage = $this->entityManager()->getStorage($processor->entityType());
     foreach ($storage->loadMultiple($entity_ids) as $entity) {
         $ago = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $entity->get('feeds_item')->imported);
         $row = [];
         // Entity link.
         $row[] = ['data' => $entity->link(Unicode::truncate($entity->label(), 75, TRUE, TRUE)), 'title' => $entity->label()];
         // Imported ago.
         $row[] = $this->t('@time ago', ['@time' => $ago]);
         // Item GUID.
         $row[] = ['data' => SafeMarkup::checkPlain(Unicode::truncate($entity->get('feeds_item')->guid, 30, FALSE, TRUE)), 'title' => $entity->get('feeds_item')->guid];
         // Item URL.
         $row[] = ['data' => SafeMarkup::checkPlain(Unicode::truncate($entity->get('feeds_item')->url, 30, FALSE, TRUE)), 'title' => $entity->get('feeds_item')->url];
         $build['table']['#rows'][] = $row;
     }
     $build['pager'] = ['#type' => 'pager'];
     $build['#title'] = $this->t('%title items', ['%title' => $feeds_feed->label()]);
     return $build;
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:32,代码来源:ItemListController.php

示例2: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $OriginalValue = '';
     if (($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof \Drupal\node\NodeInterface) {
         $FiledsView = $items->view();
         $LangCode = $items->getLangcode();
         $FieldName = $FiledsView['#field_name'];
         $node = (array) $node;
         $arrayValues = array_values($node);
         if (isset($arrayValues[0]['langcode']['x-default']) && $arrayValues[0]['langcode']['x-default'] != $LangCode) {
             if ($FieldName != 'title') {
                 if (isset($arrayValues[0][$FieldName]['x-default'][0]['value'])) {
                     $OriginalValue = $arrayValues[0][$FieldName]['x-default'][0]['value'];
                 }
             } else {
                 if (isset($arrayValues[0][$FieldName]['x-default'])) {
                     $OriginalValue = $arrayValues[0][$FieldName]['x-default'];
                 }
             }
             $Title = $OriginalValue;
             $OriginalValue = Unicode::truncate($OriginalValue, 200, TRUE);
             $OriginalValue = '<div class="original_text" title="' . $Title . '"><span class="original">ORIGINAL: </span>' . $OriginalValue . '</div>';
         }
     }
     $element['value'] = $element + array('#type' => 'textfield', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, '#size' => $this->getSetting('size'), '#placeholder' => $this->getSetting('placeholder'), '#maxlength' => $this->getFieldSetting('max_length'), '#attributes' => array('class' => array('text-full')), '#suffix' => $OriginalValue);
     return $element;
 }
开发者ID:brstde,项目名称:gap1,代码行数:30,代码来源:StringTextfieldWidget.php

示例3: prepareRow

 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $row->setSourceProperty('options', unserialize($row->getSourceProperty('options')));
     $row->setSourceProperty('enabled', !$row->getSourceProperty('hidden'));
     $row->setSourceProperty('description', Unicode::truncate($row->getSourceProperty('options/attributes/title'), 255));
     return parent::prepareRow($row);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:10,代码来源:MenuLink.php

示例4: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->databaseContents['menu_links'] = $this->expectedResults;
     // Add long link title attributes.
     $title = $this->getRandomGenerator()->string('500');
     $this->databaseContents['menu_links'][0]['options']['attributes']['title'] = $title;
     $this->expectedResults[0]['description'] = Unicode::truncate($title, 255);
     // D6 menu link to a custom menu, provided by menu module.
     $this->databaseContents['menu_links'][] = ['menu_name' => 'menu-user', 'mlid' => 143, 'plid' => 0, 'link_path' => 'admin/build/menu-customize/navigation', 'router_path' => 'admin/build/menu-customize/%', 'link_title' => 'Navigation', 'options' => array(), 'module' => 'menu', 'hidden' => 0, 'external' => 0, 'has_children' => 0, 'expanded' => 0, 'weight' => 0, 'depth' => 0, 'customized' => 0, 'p1' => '0', 'p2' => '0', 'p3' => '0', 'p4' => '0', 'p5' => '0', 'p6' => '0', 'p7' => '0', 'p8' => '0', 'p9' => '0', 'updated' => '0', 'description' => ''];
     array_walk($this->databaseContents['menu_links'], function (&$row) {
         $row['options'] = serialize($row['options']);
     });
     parent::setUp();
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:17,代码来源:MenuLinkSourceTest.php

示例5: uniquify

 /**
  * {@inheritdoc}
  */
 public function uniquify(&$alias, $source, $langcode)
 {
     $config = $this->configFactory->get('pathauto.settings');
     if (!$this->isReserved($alias, $source, $langcode)) {
         return;
     }
     // If the alias already exists, generate a new, hopefully unique, variant.
     $maxlength = min($config->get('max_length'), $this->aliasStorageHelper->getAliasSchemaMaxlength());
     $separator = $config->get('separator');
     $original_alias = $alias;
     $i = 0;
     do {
         // Append an incrementing numeric suffix until we find a unique alias.
         $unique_suffix = $separator . $i;
         $alias = Unicode::truncate($original_alias, $maxlength - Unicode::strlen($unique_suffix, TRUE)) . $unique_suffix;
         $i++;
     } while ($this->isReserved($alias, $source, $langcode));
 }
开发者ID:dev981,项目名称:gaptest,代码行数:21,代码来源:AliasUniquifier.php

示例6: cleanAlias

 /**
  * {@inheritdoc}
  */
 public function cleanAlias($alias)
 {
     if (!isset($this->aliasMaxLength)) {
         $config = $this->configFactory->get('pathauto.settings');
         $this->aliasMaxLength = min($config->get('max_length'), $this->aliasStorageHelper->getAliasSchemaMaxLength());
     }
     $output = $alias;
     // Trim duplicate, leading, and trailing separators. Do this before cleaning
     // backslashes since a pattern like "[token1]/[token2]-[token3]/[token4]"
     // could end up like "value1/-/value2" and if backslashes were cleaned first
     // this would result in a duplicate blackslash.
     $output = $this->getCleanSeparators($output);
     // Trim duplicate, leading, and trailing backslashes.
     $output = $this->getCleanSeparators($output, '/');
     // Shorten to a logical place based on word boundaries.
     $output = Unicode::truncate($output, $this->aliasMaxLength, TRUE);
     return $output;
 }
开发者ID:dev981,项目名称:gaptest,代码行数:21,代码来源:AliasCleaner.php

示例7: providerSource

 /**
  * {@inheritdoc}
  */
 public function providerSource()
 {
     $tests = [];
     // The source data.
     $tests[0]['source_data']['menu_links'] = [['menu_name' => 'menu-test-menu', 'mlid' => 140, 'plid' => 0, 'link_path' => 'admin/config/system/cron', 'router_path' => 'admin/config/system/cron', 'link_title' => 'Cron', 'options' => array(), 'module' => 'system', 'hidden' => 0, 'external' => 0, 'has_children' => 0, 'expanded' => 0, 'weight' => 0, 'depth' => 0, 'customized' => 1, 'p1' => '0', 'p2' => '0', 'p3' => '0', 'p4' => '0', 'p5' => '0', 'p6' => '0', 'p7' => '0', 'p8' => '0', 'p9' => '0', 'updated' => '0', 'description' => ''], ['menu_name' => 'menu-test-menu', 'mlid' => 141, 'plid' => 0, 'link_path' => 'node/141', 'router_path' => 'node/%', 'link_title' => 'Node 141', 'options' => array(), 'module' => 'menu', 'hidden' => 0, 'external' => 0, 'has_children' => 0, 'expanded' => 0, 'weight' => 0, 'depth' => 0, 'customized' => 1, 'p1' => '0', 'p2' => '0', 'p3' => '0', 'p4' => '0', 'p5' => '0', 'p6' => '0', 'p7' => '0', 'p8' => '0', 'p9' => '0', 'updated' => '0', 'description' => ''], ['menu_name' => 'menu-test-menu', 'mlid' => 142, 'plid' => 0, 'link_path' => 'node/142', 'router_path' => 'node/%', 'link_title' => 'Node 142', 'options' => array(), 'module' => 'menu', 'hidden' => 0, 'external' => 0, 'has_children' => 0, 'expanded' => 0, 'weight' => 0, 'depth' => 0, 'customized' => 0, 'p1' => '0', 'p2' => '0', 'p3' => '0', 'p4' => '0', 'p5' => '0', 'p6' => '0', 'p7' => '0', 'p8' => '0', 'p9' => '0', 'updated' => '0', 'description' => ''], ['menu_name' => 'menu-test-menu', 'mlid' => 138, 'plid' => 0, 'link_path' => 'admin', 'router_path' => 'admin', 'link_title' => 'Test 1', 'options' => array('attributes' => array('title' => 'Test menu link 1')), 'module' => 'menu', 'hidden' => 0, 'external' => 0, 'has_children' => 1, 'expanded' => 0, 'weight' => 15, 'depth' => 1, 'customized' => 1, 'p1' => '138', 'p2' => '0', 'p3' => '0', 'p4' => '0', 'p5' => '0', 'p6' => '0', 'p7' => '0', 'p8' => '0', 'p9' => '0', 'updated' => '0', 'description' => 'Test menu link 1'], ['menu_name' => 'menu-test-menu', 'mlid' => 139, 'plid' => 138, 'link_path' => 'admin/modules', 'router_path' => 'admin/modules', 'link_title' => 'Test 2', 'options' => array('attributes' => array('title' => 'Test menu link 2')), 'module' => 'menu', 'hidden' => 0, 'external' => 0, 'has_children' => 0, 'expanded' => 0, 'weight' => 12, 'depth' => 2, 'customized' => 1, 'p1' => '138', 'p2' => '139', 'p3' => '0', 'p4' => '0', 'p5' => '0', 'p6' => '0', 'p7' => '0', 'p8' => '0', 'p9' => '0', 'updated' => '0', 'description' => 'Test menu link 2'], ['menu_name' => 'menu-user', 'mlid' => 143, 'plid' => 0, 'link_path' => 'admin/build/menu-customize/navigation', 'router_path' => 'admin/build/menu-customize/%', 'link_title' => 'Navigation', 'options' => array(), 'module' => 'menu', 'hidden' => 0, 'external' => 0, 'has_children' => 0, 'expanded' => 0, 'weight' => 0, 'depth' => 0, 'customized' => 0, 'p1' => '0', 'p2' => '0', 'p3' => '0', 'p4' => '0', 'p5' => '0', 'p6' => '0', 'p7' => '0', 'p8' => '0', 'p9' => '0', 'updated' => '0', 'description' => '']];
     // Add long link title attributes to source data.
     $title = $this->getRandomGenerator()->string('500');
     $tests[0]['source_data']['menu_links'][0]['options']['attributes']['title'] = $title;
     // Build the expected results.
     $expected = $tests[0]['source_data']['menu_links'];
     // Add long link title attributes to expected results.
     $expected[0]['description'] = Unicode::truncate($title, 255);
     // Don't expect D6 menu link to a custom menu, provided by menu module.
     unset($expected[5]);
     array_walk($tests[0]['source_data']['menu_links'], function (&$row) {
         $row['options'] = serialize($row['options']);
     });
     $tests[0]['expected_data'] = $expected;
     return $tests;
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:23,代码来源:MenuLinkTest.php

示例8: adminOverview

 /**
  * Displays the path administration overview page.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return array
  *   A render array as expected by drupal_render().
  */
 public function adminOverview(Request $request)
 {
     $keys = $request->query->get('search');
     // Add the filter form above the overview table.
     $build['path_admin_filter_form'] = $this->formBuilder()->getForm('Drupal\\path\\Form\\PathFilterForm', $keys);
     // Enable language column if language.module is enabled or if we have any
     // alias with a language.
     $multilanguage = $this->moduleHandler()->moduleExists('language') || $this->aliasStorage->languageAliasExists();
     $header = array();
     $header[] = array('data' => $this->t('Alias'), 'field' => 'alias', 'sort' => 'asc');
     $header[] = array('data' => $this->t('System'), 'field' => 'source');
     if ($multilanguage) {
         $header[] = array('data' => $this->t('Language'), 'field' => 'langcode');
     }
     $header[] = $this->t('Operations');
     $rows = array();
     $destination = $this->getDestinationArray();
     foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) {
         $row = array();
         // @todo Should Path module store leading slashes? See
         //   https://www.drupal.org/node/2430593.
         $row['data']['alias'] = $this->l(Unicode::truncate($data->alias, 50, FALSE, TRUE), Url::fromUserInput($data->source, array('attributes' => array('title' => $data->alias))));
         $row['data']['source'] = $this->l(Unicode::truncate($data->source, 50, FALSE, TRUE), Url::fromUserInput($data->source, array('alias' => TRUE, 'attributes' => array('title' => $data->source))));
         if ($multilanguage) {
             $row['data']['language_name'] = $this->languageManager()->getLanguageName($data->langcode);
         }
         $operations = array();
         $operations['edit'] = array('title' => $this->t('Edit'), 'url' => Url::fromRoute('path.admin_edit', ['pid' => $data->pid], ['query' => $destination]));
         $operations['delete'] = array('title' => $this->t('Delete'), 'url' => Url::fromRoute('path.delete', ['pid' => $data->pid], ['query' => $destination]));
         $row['data']['operations'] = array('data' => array('#type' => 'operations', '#links' => $operations));
         // If the system path maps to a different URL alias, highlight this table
         // row to let the user know of old aliases.
         if ($data->alias != $this->aliasManager->getAliasByPath($data->source, $data->langcode)) {
             $row['class'] = array('warning');
         }
         $rows[] = $row;
     }
     $build['path_table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => $this->t('No URL aliases available. <a href=":link">Add URL alias</a>.', array(':link' => $this->url('path.admin_add'))));
     $build['path_pager'] = array('#type' => 'pager');
     return $build;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:50,代码来源:PathController.php

示例9: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     $entity = $items->getEntity();
     $settings = $this->getSettings();
     foreach ($items as $delta => $item) {
         // By default use the full URL as the link text.
         $url = $this->buildUrl($item);
         $link_title = $url->toString();
         // If the link text field value is available, use it for the text.
         if (empty($settings['url_only']) && !empty($item->title)) {
             // Unsanitized token replacement here because the entire link title
             // gets auto-escaped during link generation in
             // \Drupal\Core\Utility\LinkGenerator::generate().
             $link_title = \Drupal::token()->replace($item->title, [$entity->getEntityTypeId() => $entity], ['clear' => TRUE]);
         }
         // The link_separate formatter has two titles; the link text (as in the
         // field values) and the URL itself. If there is no link text value,
         // $link_title defaults to the URL, so it needs to be unset.
         // The URL version may need to be trimmed as well.
         if (empty($item->title)) {
             $link_title = NULL;
         }
         $url_title = $url->toString();
         if (!empty($settings['trim_length'])) {
             $link_title = Unicode::truncate($link_title, $settings['trim_length'], FALSE, TRUE);
             $url_title = Unicode::truncate($url_title, $settings['trim_length'], FALSE, TRUE);
         }
         $element[$delta] = array('#theme' => 'link_formatter_link_separate', '#title' => $link_title, '#url_title' => $url_title, '#url' => $url);
         if (!empty($item->_attributes)) {
             // Set our RDFa attributes on the <a> element that is being built.
             $url->setOption('attributes', $item->_attributes);
             // Unset field item attributes since they have been included in the
             // formatter output and should not be rendered in the field template.
             unset($item->_attributes);
         }
     }
     return $element;
 }
开发者ID:318io,项目名称:318-io,代码行数:42,代码来源:LinkSeparateFormatter.php

示例10: testTruncate

 /**
  * Tests multibyte truncate.
  *
  * @dataProvider providerTruncate
  * @covers ::truncate
  */
 public function testTruncate($text, $max_length, $expected, $wordsafe = FALSE, $add_ellipsis = FALSE)
 {
     $this->assertEquals($expected, Unicode::truncate($text, $max_length, $wordsafe, $add_ellipsis));
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:10,代码来源:UnicodeTest.php

示例11: process

 /**
  * {@inheritdoc}
  */
 public function process(FeedInterface $feed)
 {
     if (!is_array($feed->items)) {
         return;
     }
     foreach ($feed->items as $item) {
         // @todo: The default entity view builder always returns an empty
         //   array, which is ignored in aggregator_save_item() currently. Should
         //   probably be fixed.
         if (empty($item['title'])) {
             continue;
         }
         // Save this item. Try to avoid duplicate entries as much as possible. If
         // we find a duplicate entry, we resolve it and pass along its ID is such
         // that we can update it if needed.
         if (!empty($item['guid'])) {
             $values = array('fid' => $feed->id(), 'guid' => $item['guid']);
         } elseif ($item['link'] && $item['link'] != $feed->link && $item['link'] != $feed->url) {
             $values = array('fid' => $feed->id(), 'link' => $item['link']);
         } else {
             $values = array('fid' => $feed->id(), 'title' => $item['title']);
         }
         // Try to load an existing entry.
         if ($entry = entity_load_multiple_by_properties('aggregator_item', $values)) {
             $entry = reset($entry);
         } else {
             $entry = entity_create('aggregator_item', array('langcode' => $feed->language()->getId()));
         }
         if ($item['timestamp']) {
             $entry->setPostedTime($item['timestamp']);
         }
         // Make sure the item title and author fit in the 255 varchar column.
         $entry->setTitle(Unicode::truncate($item['title'], 255, TRUE, TRUE));
         $entry->setAuthor(Unicode::truncate($item['author'], 255, TRUE, TRUE));
         $entry->setFeedId($feed->id());
         $entry->setLink($item['link']);
         $entry->setGuid($item['guid']);
         $description = '';
         if (!empty($item['description'])) {
             $description = $item['description'];
         }
         $entry->setDescription($description);
         $entry->save();
     }
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:48,代码来源:DefaultProcessor.php

示例12: assertLogMessage

 /**
  * Confirms that a log message appears on the database log overview screen.
  *
  * This function should only be used for the admin/reports/dblog page, because
  * it checks for the message link text truncated to 56 characters. Other log
  * pages have no detail links so they contain the full message text.
  *
  * @param string $log_message
  *   The database log message to check.
  * @param string $message
  *   The message to pass to simpletest.
  */
 protected function assertLogMessage($log_message, $message)
 {
     $message_text = Unicode::truncate(Html::decodeEntities(strip_tags($log_message)), 56, TRUE, TRUE);
     $this->assertLink($message_text, 0, $message);
 }
开发者ID:318io,项目名称:318-io,代码行数:17,代码来源:DbLogTest.php

示例13: recurseTableOfContents

 /**
  * Recursively processes and formats book links for getTableOfContents().
  *
  * This helper function recursively modifies the table of contents array for
  * each item in the book tree, ignoring items in the exclude array or at a
  * depth greater than the limit. Truncates titles over thirty characters and
  * appends an indentation string incremented by depth.
  *
  * @param array $tree
  *   The data structure of the book's outline tree. Includes hidden links.
  * @param string $indent
  *   A string appended to each node title. Increments by '--' per depth
  *   level.
  * @param array $toc
  *   Reference to the table of contents array. This is modified in place, so
  *   the function does not have a return value.
  * @param array $exclude
  *   Optional array of Node ID values. Any link whose node ID is in this
  *   array will be excluded (along with its children).
  * @param int $depth_limit
  *   Any link deeper than this value will be excluded (along with its
  *   children).
  */
 protected function recurseTableOfContents(array $tree, $indent, array &$toc, array $exclude, $depth_limit)
 {
     $nids = array();
     foreach ($tree as $data) {
         if ($data['link']['depth'] > $depth_limit) {
             // Don't iterate through any links on this level.
             return;
         }
         if (!in_array($data['link']['nid'], $exclude)) {
             $nids[] = $data['link']['nid'];
         }
     }
     $nodes = $this->entityManager->getStorage('node')->loadMultiple($nids);
     foreach ($tree as $data) {
         $nid = $data['link']['nid'];
         // Check for excluded or missing node.
         if (empty($nodes[$nid])) {
             continue;
         }
         $toc[$nid] = $indent . ' ' . Unicode::truncate($nodes[$nid]->label(), 30, TRUE, TRUE);
         if ($data['below']) {
             $this->recurseTableOfContents($data['below'], $indent . '--', $toc, $exclude, $depth_limit);
         }
     }
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:48,代码来源:BookManager.php

示例14: overview

 /**
  * Displays a listing of database log messages.
  *
  * Messages are truncated at 56 chars.
  * Full-length messages can be viewed on the message details page.
  *
  * @return array
  *   A render array as expected by drupal_render().
  *
  * @see dblog_clear_log_form()
  * @see dblog_event()
  */
 public function overview()
 {
     $filter = $this->buildFilterQuery();
     $rows = array();
     $classes = static::getLogLevelClassMap();
     $this->moduleHandler->loadInclude('dblog', 'admin.inc');
     $build['dblog_filter_form'] = $this->formBuilder->getForm('Drupal\\dblog\\Form\\DblogFilterForm');
     $build['dblog_clear_log_form'] = $this->formBuilder->getForm('Drupal\\dblog\\Form\\DblogClearLogForm');
     $header = array('', array('data' => $this->t('Type'), 'field' => 'w.type', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), array('data' => $this->t('Date'), 'field' => 'w.wid', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)), $this->t('Message'), array('data' => $this->t('User'), 'field' => 'u.name', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), array('data' => $this->t('Operations'), 'class' => array(RESPONSIVE_PRIORITY_LOW)));
     $query = $this->database->select('watchdog', 'w')->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender');
     $query->fields('w', array('wid', 'uid', 'severity', 'type', 'timestamp', 'message', 'variables', 'link'));
     if (!empty($filter['where'])) {
         $query->where($filter['where'], $filter['args']);
     }
     $result = $query->limit(50)->orderByHeader($header)->execute();
     foreach ($result as $dblog) {
         $message = $this->formatMessage($dblog);
         if ($message && isset($dblog->wid)) {
             // Truncate link_text to 56 chars of message.
             $log_text = Unicode::truncate(Xss::filter($message, array()), 56, TRUE, TRUE);
             $message = $this->l($log_text, 'dblog.event', array('event_id' => $dblog->wid), array('html' => TRUE));
         }
         $username = array('#theme' => 'username', '#account' => user_load($dblog->uid));
         $rows[] = array('data' => array(array('class' => array('icon')), $this->t($dblog->type), $this->dateFormatter->format($dblog->timestamp, 'short'), $message, array('data' => $username), Xss::filter($dblog->link)), 'class' => array(drupal_html_class('dblog-' . $dblog->type), $classes[$dblog->severity]));
     }
     $build['dblog_table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array('id' => 'admin-dblog', 'class' => array('admin-dblog')), '#empty' => $this->t('No log messages available.'), '#attached' => array('library' => array('dblog/drupal.dblog')));
     $build['dblog_pager'] = array('#theme' => 'pager');
     return $build;
 }
开发者ID:shumer,项目名称:blog,代码行数:41,代码来源:DbLogController.php

示例15: getAllEvents

 protected function getAllEvents(DrupalStyle $io, $eventType, $eventSeverity, $userId, $asc, $offset, $limit)
 {
     $connection = $this->getDrupalService('database');
     $dateFormatter = $this->getDrupalService('date.formatter');
     $userStorage = $this->getDrupalService('entity_type.manager')->getStorage('user');
     $severity = RfcLogLevel::getLevels();
     $query = $connection->select('watchdog', 'w');
     $query->fields('w', ['wid', 'uid', 'severity', 'type', 'timestamp', 'message', 'variables']);
     if ($eventType) {
         $query->condition('type', $eventType);
     }
     if ($eventSeverity) {
         if (!in_array($eventSeverity, $severity)) {
             $io->error(sprintf($this->trans('commands.database.log.debug.messages.invalid-severity'), $eventSeverity));
             return false;
         }
         $query->condition('severity', array_search($eventSeverity, $severity));
     }
     if ($userId) {
         $query->condition('uid', $userId);
     }
     if ($asc) {
         $query->orderBy('wid', 'ASC');
     } else {
         $query->orderBy('wid', 'DESC');
     }
     if ($limit) {
         $query->range($offset, $limit);
     }
     $result = $query->execute();
     $tableHeader = [$this->trans('commands.database.log.debug.messages.event-id'), $this->trans('commands.database.log.debug.messages.type'), $this->trans('commands.database.log.debug.messages.date'), $this->trans('commands.database.log.debug.messages.message'), $this->trans('commands.database.log.debug.messages.user'), $this->trans('commands.database.log.debug.messages.severity')];
     $tableRows = [];
     foreach ($result as $dblog) {
         $user = $userStorage->load($dblog->uid);
         $tableRows[] = [$dblog->wid, $dblog->type, $dateFormatter->format($dblog->timestamp, 'short'), Unicode::truncate(Html::decodeEntities(strip_tags($this->formatMessage($dblog))), 56, true, true), $user->getUsername() . ' (' . $user->id() . ')', $severity[$dblog->severity]];
     }
     $io->table($tableHeader, $tableRows);
     return true;
 }
开发者ID:mnico,项目名称:DrupalConsole,代码行数:39,代码来源:LogDebugCommand.php


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