You are here

class DblogMessage in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/dblog/src/Plugin/views/field/DblogMessage.php \Drupal\dblog\Plugin\views\field\DblogMessage
  2. 9 core/modules/dblog/src/Plugin/views/field/DblogMessage.php \Drupal\dblog\Plugin\views\field\DblogMessage

Provides a field handler that renders a log event with replaced variables.

Plugin annotation

@ViewsField("dblog_message");

Hierarchy

  • class \Drupal\dblog\Plugin\views\field\DblogMessage extends \Drupal\views\Plugin\views\field\FieldPluginBase

Expanded class hierarchy of DblogMessage

File

core/modules/dblog/src/Plugin/views/field/DblogMessage.php, line 19

Namespace

Drupal\dblog\Plugin\views\field
View source
class DblogMessage extends FieldPluginBase {

  /**
   * {@inheritdoc}
   */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view, $display, $options);
    if ($this->options['replace_variables']) {
      $this->additional_fields['variables'] = 'variables';
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['replace_variables'] = [
      'default' => TRUE,
    ];
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $form['replace_variables'] = [
      '#title' => $this
        ->t('Replace variables'),
      '#type' => 'checkbox',
      '#default_value' => $this->options['replace_variables'],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    $value = $this
      ->getValue($values);
    if ($this->options['replace_variables']) {
      $variables = unserialize($this
        ->getvalue($values, 'variables'));
      return new FormattableMarkup($value, (array) $variables);
    }
    else {
      return $this
        ->sanitizeValue($value);
    }
  }

}

Members