clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
<?php
namespace Drupal\log\Plugin\Action;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TempStore\PrivateTempStore;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Base class for the configurable actions for logs.
*/
abstract class LogActionBase extends ActionBase implements DependentPluginInterface, ContainerFactoryPluginInterface {
/**
* The tempstore object.
*
* @var \Drupal\Core\TempStore\PrivateTempStore
*/
protected $tempStore;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $user;
/**
* Constructs a LogActionBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\TempStore\PrivateTempStore $temp_store
* The tempstore factory.
* @param \Drupal\Core\Session\AccountInterface $user
* The current user.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, PrivateTempStore $temp_store, AccountInterface $user) {
$this->tempStore = $temp_store;
$this->user = $user;
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$temp_store = $container->get('tempstore.private')->get($plugin_id);
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$temp_store,
$container->get('current_user')
);
}
/**
* {@inheritdoc}
*/
public function executeMultiple(array $entities) {
$this->tempStore->set($this->user->id(), $entities);
}
/**
* {@inheritdoc}
*/
public function execute($object = NULL) {
$this->executeMultiple([$object]);
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\log\Entity\LogInterface $object */
return $object->access('update', $account, $return_as_object);
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Drupal\log\Plugin\Action;
use Drupal\Core\Session\AccountInterface;
/**
* Action that clones a log entity.
*
* @Action(
* id = "log_clone_action",
* label = @Translation("Clones a log"),
* type = "log",
* confirm_form_route_name = "log.log_clone_action_form"
* )
*/
class LogClone extends LogActionBase {
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\log\Entity\LogInterface $object */
$result = $object->access('view', $account, TRUE)
->andIf($object->access('create', $account, TRUE));
return $return_as_object ? $result : $result->isAllowed();
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Drupal\log\Plugin\Action;
/**
* Action that marks a log as done.
*
* @Action(
* id = "log_mark_as_done_action",
* label = @Translation("Sets a Log as done"),
* type = "log"
* )
*/
class LogMarkAsDone extends LogStateChangeBase {
/**
* {@inheritdoc}
*/
protected $targetState = 'done';
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Drupal\log\Plugin\Action;
/**
* Action that marks a log as pending.
*
* @Action(
* id = "log_mark_as_pending_action",
* label = @Translation("Sets a Log as pending"),
* type = "log"
* )
*/
class LogMarkAsPending extends LogStateChangeBase {
/**
* {@inheritdoc}
*/
protected $targetState = 'pending';
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Drupal\log\Plugin\Action;
use Drupal\Core\Session\AccountInterface;
/**
* Action that reschedules a log entity.
*
* @Action(
* id = "log_reschedule_action",
* label = @Translation("Reschedules a log"),
* type = "log",
* confirm_form_route_name = "log.log_schedule_action_form"
* )
*/
class LogReschedule extends LogActionBase {
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\log\Entity\LogInterface $object */
$result = $object->get('timestamp')->access('edit', $account, TRUE)
->andIf($object->access('update', $account, TRUE));
return $return_as_object ? $result : $result->isAllowed();
}
}

View File

@@ -0,0 +1,111 @@
<?php
namespace Drupal\log\Plugin\Action;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Action\Plugin\Action\EntityActionBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\log\Entity\LogInterface;
/**
* Base class for actions that change the log status state.
*/
abstract class LogStateChangeBase extends EntityActionBase {
/**
* The target state to transition to.
*
* @var string
*/
protected $targetState;
/**
* {@inheritdoc}
*/
public function execute(LogInterface $log = NULL) {
// Bail if there is no log.
if (empty($log)) {
return;
}
// Apply the transition to target state if not already the current state.
/** @var \Drupal\state_machine\Plugin\Field\FieldType\StateItemInterface $state_item */
$state_item = $log->get('status')->first();
if ($state_item->getOriginalId() !== $this->targetState && $transition = $state_item->getWorkflow()->findTransition($state_item->getOriginalId(), $this->targetState)) {
$state_item->applyTransition($transition);
$log->setNewRevision(TRUE);
// Validate the entity before saving.
$violations = $log->validate();
if ($violations->count() > 0) {
$this->messenger()->addWarning(
$this->t('Could not change the status of <a href=":entity_link">%entity_label</a>: validation failed.',
[
':entity_link' => $log->toUrl()->setAbsolute()->toString(),
'%entity_label' => $log->label(),
],
),
);
return;
}
$log->save();
}
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\log\Entity\LogInterface $object */
// First check entity and state field access.
$result = $object->get('status')->access('edit', $account, TRUE)
->andIf($object->access('update', $account, TRUE));
// Save the state field.
/** @var \Drupal\state_machine\Plugin\Field\FieldType\StateItemInterface $state_item */
$state_item = $object->get('status')->first();
// If the state field is already in the target state, return early.
// The workflow will not allow a transition to the same state but the
// action itself does not need to fail.
if ($state_item->getOriginalId() === $this->targetState) {
return $return_as_object ? $result : $result->isAllowed();
}
// Check that the target state exists for the workflow.
$workflow = $state_item->getWorkflow();
$target_state = $workflow->getState($this->targetState);
// Deny access if the workflow does not support the target state.
if (empty($target_state)) {
$result = $result->orIf(AccessResult::forbidden(
$this->t(
'The %workflow workflow does not support the %target_state state.',
[
'%workflow' => $workflow->getLabel(),
'%target_state' => $this->targetState,
],
),
));
}
// Else check that a transition exists to the desired target state.
else {
$transition = $workflow->findTransition($state_item->getOriginalId(), $this->targetState);
$result = $result->orIf(AccessResult::forbiddenIf(
empty($transition) || !$state_item->isTransitionAllowed($transition->getId()),
$this->t(
'The state transition from %original_state to %target_state is not allowed.',
[
'%original' => $state_item->getOriginalLabel(),
'%target_state' => $target_state->getLabel(),
],
),
));
}
return $return_as_object ? $result : $result->isAllowed();
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace Drupal\log\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
/**
* Log source from database.
*
* @MigrateSource(
* id = "d7_log",
* source_module = "log"
* )
*/
class Log extends FieldableEntity {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('log', 'l')
->fields('l')
->distinct()
->orderBy('id');
if (isset($this->configuration['bundle'])) {
$query->condition('l.type', (array) $this->configuration['bundle'], 'IN');
}
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'id' => $this->t('The log ID'),
'name' => $this->t('The log name'),
'type' => $this->t('The log type'),
'uid' => $this->t('The log author ID'),
'timestamp' => $this->t('Timestamp of the event being logged'),
'created' => $this->t('Timestamp when the log was created'),
'changed' => $this->t('Timestamp when the log was last modified'),
'done' => $this->t('Boolean indicating whether the log is done (the event happened)'),
];
return $fields;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$id = $row->getSourceProperty('id');
$type = $row->getSourceProperty('type');
// Get Field API field values.
foreach ($this->getFields('log', $type) as $field_name => $field) {
$row->setSourceProperty($field_name, $this->getFieldValues('log', $field_name, $id));
}
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['id']['type'] = 'integer';
return $ids;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Drupal\log\Plugin\views\field;
use Drupal\views\Plugin\views\field\EntityField;
/**
* Field handler to enable custom click-sort behavior for timestamp and id.
*
* @ViewsField("log_field")
*/
class LogField extends EntityField {
/**
* {@inheritdoc}
*/
public function clickSort($order) {
// No column selected, can't continue.
if (empty($this->options['click_sort_column'])) {
return;
}
$this->ensureMyTable();
$field_storage_definition = $this->getFieldStorageDefinition();
$column = $this->getTableMapping()->getFieldColumnName($field_storage_definition, $this->options['click_sort_column']);
if (!isset($this->aliases[$column])) {
// Column is not in query; add a sort on it (without adding the column).
$this->aliases[$column] = $this->tableAlias . '.' . $column;
}
$this->query->addOrderBy(NULL, NULL, $order, $this->aliases[$column]);
$this->query->addOrderBy($this->tableAlias, 'id', $order);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Drupal\log\Plugin\views\sort;
use Drupal\views\Plugin\views\sort\Date;
/**
* Sort handler for logs based on timestamp and id.
*
* @ViewsSort("log_standard")
*/
class LogStandardSort extends Date {
/**
* {@inheritdoc}
*/
public function query() {
$this->ensureMyTable();
switch ($this->options['granularity']) {
case 'second':
default:
$this->query->addOrderBy($this->tableAlias, $this->realField, $this->options['order']);
$this->query->addOrderBy($this->tableAlias, 'id', $this->options['order']);
return;
case 'minute':
$formula = $this->getDateFormat('YmdHi');
break;
case 'hour':
$formula = $this->getDateFormat('YmdH');
break;
case 'day':
$formula = $this->getDateFormat('Ymd');
break;
case 'month':
$formula = $this->getDateFormat('Ym');
break;
case 'year':
$formula = $this->getDateFormat('Y');
break;
}
$this->query->addOrderBy(NULL, $formula, $this->options['order'], $this->tableAlias . '_' . $this->field . '_' . $this->options['granularity']);
$this->query->addOrderBy($this->tableAlias, 'id', $this->options['order']);
}
/**
* {@inheritdoc}
*/
public function getDateField() {
return $this->query->getDateField("$this->tableAlias.timestamp");
}
}