Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/Plugin/DataType/LoggerEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* @file
* Contains \Drupal\rules\Plugin\DataType\LoggerEntry.
*/

namespace Drupal\rules\Plugin\DataType;

use Drupal\Core\TypedData\Plugin\DataType\Map;

/**
* The logger entry data type.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we describe what this is? Example "Represents a log entry that is created from system log messages."

*
* @see: https://www.drupal.org/node/2625238
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "@see" annotations should not have a colon after it, see https://www.drupal.org/coding-standards/docs#see

*
* @ingroup typed_data
*
* @DataType(
* id = "loggerentry",
* label = @Translation("Logger Entry"),
* definition_class = "\Drupal\Core\TypedData\MapDataDefinition"
* )
*/
class LoggerEntry extends Map {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can look at examples for typed data in core: Language.php


/**
* The data definition.
*
* @var \Drupal\Core\TypedData\ComplexDataDefinitionInterface
*/
protected $definition;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that property already exists on the parent class.


/**
* An array of values for the contained properties.
*
* @var array
*/
protected $values = array();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that property already exists on the parent class.


/**
* The array of properties.
*
* @var \Drupal\Core\TypedData\TypedDataInterface[]
*/
protected $properties = array();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that property already exists on the parent class.


public function __construct(DataDefinitionInterface $definition, $name, TypedDataInterface $parent, $logger_entry_context) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the constructor should not take the logger_entry array values, typed data is always set with the setValue() method.

parent::__construct($definition, $name, $parent);

$this->values = $this->createLoggerEntryFromContext($logger_entry_context)
}

// Plain copy from \Drupal\rules\Logger\RulesLog
protected function createLoggerEntryFromContext($context) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method is not needed. The caller can just use ->setValue() and pass in the array. Almost all properties are primitives/strings except for variables.

// Remove any backtraces since they may contain an unserializable variable.
unset($context['backtrace']);

// Convert PSR3-style messages to SafeMarkup::format() style, so they can be
// translated too in runtime.
$message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);

$logger_entry = array(
'uid' => $context['uid'],
'type' => $context['channel'],
'message' => $message,
'variables' => $message_placeholders,
'severity' => $level,
'link' => $context['link'],
'location' => $context['request_uri'],
'referer' => $context['referer'],
'hostname' => $context['ip'],
'timestamp' => $context['timestamp'],
);

return $logger_entry;
}
}