class Message

Same name in this branch
  1. 8.x-1.x src/Entity/Message.php \Drupal\tmgmt\Entity\Message
  2. 8.x-1.x src/Plugin/views/field/Message.php \Drupal\tmgmt\Plugin\views\field\Message

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

Plugin annotation

@ViewsField("tmgmt_message");

Hierarchy

  • class \Drupal\tmgmt\Plugin\views\field\Message extends \Drupal\views\Plugin\views\field\FieldPluginBase

Expanded class hierarchy of Message

1 string reference to 'Message'

File

src/Plugin/views/field/Message.php, line 19

Namespace

Drupal\tmgmt\Plugin\views\field
View source
class Message 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'] = array(
      'default' => TRUE,
      'bool' => TRUE,
    );
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $form['replace_variables'] = array(
      '#title' => 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

Namesort descending Modifiers Type Description Overrides
Message::buildOptionsForm public function
Message::defineOptions protected function
Message::init public function
Message::render public function