class ReplicationListBuilder in Deploy - Content Staging 8
Defines a class to build a listing of Replication entities.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
- class \Drupal\deploy\ReplicationListBuilder
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
Expanded class hierarchy of ReplicationListBuilder
File
- src/
ReplicationListBuilder.php, line 20
Namespace
Drupal\deployView source
class ReplicationListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['replication_status'] = $this
->t('Status');
$header['name'] = $this
->t('Title');
$header['source'] = $this
->t('Source');
$header['target'] = $this
->t('Target');
$header['changed'] = $this
->t('Updated');
$header['created'] = $this
->t('Created');
$header['user'] = $this
->t('User');
$header['description'] = $this
->t('Description');
$header['operations'] = $this
->t('Operations');
return $header;
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$formatter = \Drupal::service('date.formatter');
/* @var $entity \Drupal\workspace\Entity\Replication */
$row['replication_status'] = $this
->getReplicationStatusIcon($entity
->getReplicationStatus(), $entity
->id());
$row['name'] = $entity
->label();
$row['source'] = $entity
->get('source')->entity ? $entity
->get('source')->entity
->label() : $this
->t('<em>Unknown</em>');
$row['target'] = $entity
->get('target')->entity ? $entity
->get('target')->entity
->label() : $this
->t('<em>Unknown</em>');
$user = User::load($entity->uid->target_id);
$row['changed'] = $formatter
->format($entity
->getChangedTime());
$row['created'] = $formatter
->format($entity
->getCreatedTime());
$row['user'] = $user
->getAccountName();
$row['description'] = $entity->description->value;
// Set operations.
$links = [];
if ($entity
->hasLinkTemplate('delete-form') && in_array($entity
->getReplicationStatus(), [
Replication::REPLICATED,
Replication::FAILED,
])) {
$links['delete'] = [
'title' => t('Delete'),
'url' => $entity
->toUrl('delete-form', [
'absolute' => TRUE,
]),
];
}
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
return $row;
}
/**
* {@inheritdoc}
*/
public function render() {
// Determine when cron last ran.
$cron_last = \Drupal::state()
->get('system.cron_last');
if (!is_numeric($cron_last)) {
$cron_last = \Drupal::state()
->get('install_time', 0);
}
$build = [];
$build['#markup'] = '';
if (\Drupal::state()
->get('workspace.last_replication_failed', FALSE)) {
$message = $this
->generateMessageRenderArray('warning', $this
->t('Creation of new deployments has been blocked due to a failure. Contact your administrator to get the issue resolved and deployments unblocked.'));
$user_has_access = \Drupal::currentUser()
->hasPermission('administer site configuration');
if ($user_has_access) {
$message = $this
->generateMessageRenderArray('warning', $this
->t('Creation of new deployments has been blocked due to a failure. After resolving the issue, go to the <a href="@url">replication settings</a> page to unblock deployments.', [
'@url' => '/admin/config/replication/settings',
]));
}
elseif ($support_email = Settings::get('support_email_address', NULL)) {
$message = $this
->generateMessageRenderArray('warning', $this
->t('Creating new deployments is not allowed at the moment. Please contact the <a href="mailto:@url">support team</a> to unblock creating new content deployments.', [
'@url' => $support_email,
]));
}
$build['#markup'] .= \Drupal::service('renderer')
->render($message);
}
$build['#markup'] .= $this
->t('Last cron ran @time ago', [
'@time' => \Drupal::service('date.formatter')
->formatTimeDiffSince($cron_last),
]);
$build += parent::render();
return $build;
}
/**
* Loads entity IDs using a pager sorted by the entity id.
*
* @return array
* An array of entity IDs.
*/
protected function getEntityIds() {
$query = $this
->getStorage()
->getQuery()
->sort('changed', 'DESC');
// Only add the pager if a limit is specified.
if ($this->limit) {
$query
->pager($this->limit);
}
return $query
->execute();
}
protected function getReplicationStatusIcon($status, $id) {
$status = (int) $status;
$icons = [
Replication::QUEUED => $this
->t('⌚ Queued'),
Replication::REPLICATING => $this
->t('In progress'),
Replication::REPLICATED => $this
->t('✔ Done'),
];
if ($status === Replication::FAILED) {
$link_url = Url::fromUserInput('/admin/structure/deployment/' . $id . '/fail-info');
$link_url
->setOptions(array(
'attributes' => array(
'class' => array(
'use-ajax',
),
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode(array(
'width' => 700,
)),
),
));
$icons[Replication::FAILED] = Link::fromTextAndUrl($this
->t('✖ Failed'), $link_url);
}
/** @var Replication $entity */
$entity = $this
->getStorage()
->load($id);
if ($status === Replication::QUEUED && !empty($entity
->getReplicationFailInfo())) {
$link_url = Url::fromUserInput('/admin/structure/deployment/' . $id . '/requeue-info');
$link_url
->setOptions(array(
'attributes' => array(
'class' => array(
'use-ajax',
),
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode(array(
'width' => 700,
)),
),
));
$icons[Replication::QUEUED] = Link::fromTextAndUrl($this
->t('⌚ Queued'), $link_url);
}
return $icons[$status];
}
/**
* Generate a message render array with the given text.
*
* @param string $type
* The type of message: status, warning, or error.
* @param string $message
* The message to create with.
*
* @return array
* The render array for a status message.
*
* @see \Drupal\Core\Render\Element\StatusMessages
*/
protected function generateMessageRenderArray($type, $message) {
return [
'#theme' => 'status_messages',
'#message_list' => [
$type => [
Markup::create($message),
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityHandlerBase:: |
protected | property | The module handler to invoke hooks on. | 2 |
EntityHandlerBase:: |
protected | function | Gets the module handler. | 2 |
EntityHandlerBase:: |
public | function | Sets the module handler for this handler. | |
EntityListBuilder:: |
protected | property | Information about the entity type. | |
EntityListBuilder:: |
protected | property | The entity type ID. | |
EntityListBuilder:: |
protected | property | The number of entities to list per page, or FALSE to list all entities. | 3 |
EntityListBuilder:: |
protected | property | The entity storage class. | 1 |
EntityListBuilder:: |
public | function | Builds a renderable list of operation links for the entity. | 2 |
EntityListBuilder:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
20 |
EntityListBuilder:: |
protected | function | Ensures that a destination is present on the given URL. | |
EntityListBuilder:: |
protected | function | Gets this list's default operations. | 2 |
EntityListBuilder:: |
protected | function | Gets the label of an entity. | |
EntityListBuilder:: |
public | function |
Provides an array of information to build a list of operation links. Overrides EntityListBuilderInterface:: |
2 |
EntityListBuilder:: |
public | function |
Gets the entity storage. Overrides EntityListBuilderInterface:: |
|
EntityListBuilder:: |
protected | function | Gets the title of the page. | 1 |
EntityListBuilder:: |
public | function |
Loads entities of this type from storage for listing. Overrides EntityListBuilderInterface:: |
4 |
EntityListBuilder:: |
public | function | Constructs a new EntityListBuilder object. | 16 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
ReplicationListBuilder:: |
public | function |
Builds the header row for the entity listing. Overrides EntityListBuilder:: |
|
ReplicationListBuilder:: |
public | function |
Builds a row for an entity in the entity listing. Overrides EntityListBuilder:: |
|
ReplicationListBuilder:: |
protected | function | Generate a message render array with the given text. | |
ReplicationListBuilder:: |
protected | function |
Loads entity IDs using a pager sorted by the entity id. Overrides EntityListBuilder:: |
|
ReplicationListBuilder:: |
protected | function | ||
ReplicationListBuilder:: |
public | function |
Builds the entity listing as renderable array for table.html.twig. Overrides EntityListBuilder:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |