formatMessage example


  public function testDbLogCorrupted() {
    $dblog_controller = DbLogController::create($this->container);

    // Check message with properly serialized data.     $message = (object) [
      'message' => 'Sample message with placeholder: @placeholder',
      'variables' => serialize(['@placeholder' => 'test placeholder']),
    ];

    $this->assertEquals('Sample message with placeholder: test placeholder', $dblog_controller->formatMessage($message));

    // Check that controller work with corrupted data.     $message->variables = 'BAD SERIALIZED DATA';
    $formatted = $dblog_controller->formatMessage($message);
    $this->assertEquals('Log data is corrupted and cannot be unserialized: Sample message with placeholder: @placeholder', $formatted);
  }

}

function hook_views_analyze(\Drupal\views\ViewExecutable $view) {
  $messages = [];

  if ($view->display_handler->options['pager']['type'] == 'none') {
    $messages[] = Drupal\views\Analyzer::formatMessage(t('This view has no pager. This could cause performance issues when the view contains many items.'), 'warning');
  }

  return $messages;
}

/** * Describe data tables and fields (or the equivalent) to Views. * * The table and fields are processed in Views using various plugins. See * the @link views_plugins Views plugins topic @endlink for more information. * * To provide views data for an entity, instead of implementing this hook, * create a class implementing \Drupal\views\EntityViewsDataInterface and * reference this in the "handlers.views_data" annotation in the entity class. * The return value of the getViewsData() method on the interface is the same as * this hook, and base class in \Drupal\views\EntityViewsData will take care of * adding the basic Views tables and fields for your entity. See the * @link entity_api Entity API topic @endlink for more information about * entities. * * The data described with this hook is fetched and retrieved by * \Drupal\views\Views::viewsData()->get(). * * @return array * An associative array describing the structure of database tables and fields * (and their equivalents) provided for use in Views. At the outermost level, * the keys are the names used internally by Views for the tables (usually the * actual table name). Each table's array describes the table itself, how to * join to other tables, and the fields that are part of the table. The sample * function body provides documentation of the details. * * @see hook_views_data_alter() */
        // also when adding a new translation.         $latest_affected_revision_id = 1;
      }
      $previous_revision_id = (int) $entity->getLoadedRevisionId();
      /** @var \Drupal\Core\Entity\ContentEntityInterface $latest_affected_revision */
      $latest_affected_revision = $this->storage->loadRevision($latest_affected_revision_id);
      $translation = $latest_affected_revision->hasTranslation($active_langcode) ?
        $latest_affected_revision->getTranslation($active_langcode) : $latest_affected_revision->addTranslation($active_langcode);
      $entity = $this->storage->createRevision($translation$default_revision);
      $this->assertEquals($default_revision$entity->isDefaultRevision());
      $this->assertEquals($translation->getLoadedRevisionId()$entity->getLoadedRevisionId());
      $this->assertEquals($previous_label$entity->label()$this->formatMessage('Loaded translatable field value does not match the previous one.'));
    }

    // Check that the previous untranslatable field value is loaded in the new     // revision as expected. When we are dealing with a non default translation     // the expected value is always the one stored in the default revision, as     // untranslatable fields can only be changed in the default translation or     // in the default revision, depending on the configured mode.     $value = $entity->get('non_mul_field')->value;
    if (isset($previous_untranslatable_field_value)) {
      $this->assertEquals($previous_untranslatable_field_value$value$this->formatMessage('Loaded untranslatable field value does not match the previous one.'));
    }
    
$query->leftJoin('users_field_data', 'ufd', '[w].[uid] = [ufd].[uid]');

    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)) {
        $title = Unicode::truncate(Html::decodeEntities(strip_tags($message)), 256, TRUE, TRUE);
        $log_text = Unicode::truncate($title, 56, TRUE, TRUE);
        // The link generator will escape any unsafe HTML entities in the final         // text.         $message = Link::fromTextAndUrl($log_textnew Url('dblog.event', ['event_id' => $dblog->wid][
          'attributes' => [
            // Provide a title for the link for useful hover hints. The             // Attribute object will escape any unsafe HTML entities in the             // final text.             'title' => $title,
          ],


  /** * Formats the analyze result into a message string. * * This is based upon the format of * \Drupal\Core\Messenger\MessengerInterface::addMessage() which uses separate * boxes for "ok", "warning" and "error". */
  public function formatMessages(array $messages) {
    if (empty($messages)) {
      $messages = [static::formatMessage(t('View analysis can find nothing to report.'), 'ok')];
    }

    $types = ['ok' => [], 'warning' => [], 'error' => []];
    foreach ($messages as $message) {
      if (empty($types[$message['type']])) {
        $types[$message['type']] = [];
      }
      $types[$message['type']][] = $message['message'];
    }

    $output = '';
    
/** * Parses the language string for a file, loads the file, if necessary, * getting the line. * * @return string|string[] */
    public function getLine(string $line, array $args = [])
    {
        // if no file is given, just parse the line         if (strpos($line, '.') === false) {
            return $this->formatMessage($line$args);
        }

        // Parse out the file name and the actual alias.         // Will load the language file and strings.         [$file$parsedLine] = $this->parseLine($line$this->locale);

        $output = $this->getTranslationOutput($this->locale, $file$parsedLine);

        if ($output === null && strpos($this->locale, '-')) {
            [$locale] = explode('-', $this->locale, 2);

            [
Home | Imprint | This part of the site doesn't use cookies.