protected function DebugForm::debugEntity in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Form/DebugForm.php \Drupal\cms_content_sync\Form\DebugForm::debugEntity()
- 2.0.x src/Form/DebugForm.php \Drupal\cms_content_sync\Form\DebugForm::debugEntity()
Parameters
array $result: The table render array
\Drupal\Core\Entity\EntityInterface $entity:
array $parent_entities: Entities that have already been processed up the ladder
1 call to DebugForm::debugEntity()
- DebugForm::inspectEntity in src/
Form/ DebugForm.php - Display debug output for a given entity to analyze it's sync structure.
File
- src/
Form/ DebugForm.php, line 278
Class
- DebugForm
- Content Sync advanced debug form.
Namespace
Drupal\cms_content_sync\FormCode
protected function debugEntity(&$result, $entity, $parent_entities = []) {
$label = str_repeat('+', count($parent_entities)) . ' ';
/*foreach($parent_entities as $parent_entity) {
$label .= $parent_entity->label().' => ';
}*/
$label .= $entity
->label();
$moduleHandler = \Drupal::service('module_handler');
$dblog_enabled = $moduleHandler
->moduleExists('dblog');
if ($dblog_enabled) {
$connection = \Drupal::database();
$log_levels = RfcLogLevel::getLevels();
}
else {
\Drupal::messenger()
->addMessage('dblog is disabled, so no log messages will be displayed.');
}
$children = [];
$infos = EntityStatus::getInfosForEntity($entity
->getEntityTypeId(), $entity
->uuid());
if (!count($infos)) {
return;
}
foreach ($infos as $index => $info) {
$current_row = [];
if (0 == $index) {
$current_row['label'] = [
'#markup' => $label,
];
$current_row['entity_type'] = [
'#markup' => $entity
->getEntityTypeId(),
];
$current_row['bundle'] = [
'#markup' => $entity
->bundle(),
];
$current_row['id'] = [
'#markup' => $entity
->id(),
];
$current_row['uuid'] = [
'#markup' => $entity
->uuid(),
];
}
else {
$current_row['label'] = [
'#markup' => '',
];
$current_row['entity_type'] = [
'#markup' => '',
];
$current_row['bundle'] = [
'#markup' => '',
];
$current_row['id'] = [
'#markup' => '',
];
$current_row['uuid'] = [
'#markup' => '',
];
}
$flow = $info
->getFlow();
$pool = $info
->getPool();
$current_row['entity_status_id'] = [
'#markup' => $info->id->value,
];
$current_row['flow'] = [
'#markup' => $flow ? $flow
->label() : $info
->get('flow')->value,
];
$current_row['pool'] = [
'#markup' => $pool ? $pool
->label() : $info
->get('pool')->value,
];
$current_row['flags'] = [
'#theme' => 'item_list',
];
if ($info
->isSourceEntity()) {
$current_row['flags']['#items'][]['#markup'] = 'Source';
}
if ($info
->isManualPushEnabled()) {
$current_row['flags']['#items'][]['#markup'] = 'Pushing enabled';
}
if ($info
->didUserEnablePush()) {
$current_row['flags']['#items'][]['#markup'] = 'Pushed by user';
}
if ($info
->isPushedAsDependency()) {
$current_row['flags']['#items'][]['#markup'] = 'Pushed as dependency';
}
if ($info
->isOverriddenLocally()) {
$current_row['flags']['#items'][]['#markup'] = 'Overridden locally';
}
$timestamp = $info
->getLastPush();
$current_row['last_export'] = [
'#markup' => $timestamp ? \Drupal::service('date.formatter')
->format($timestamp, 'long') : 'NEVER',
];
$timestamp = $info
->getLastPull();
$current_row['last_import'] = [
'#markup' => $timestamp ? \Drupal::service('date.formatter')
->format($timestamp, 'long') : 'NEVER',
];
$current_row['log_messages'] = [
'#theme' => 'item_list',
'#items' => [],
];
$query = $connection
->select('watchdog', 'w')
->fields('w', [
'timestamp',
'severity',
'message',
'variables',
])
->orderBy('timestamp', 'DESC')
->range(0, 3)
->condition('type', 'cms_content_sync')
->condition('variables', '%' . $connection
->escapeLike($entity
->uuid()) . '%', 'LIKE');
$query = $query
->execute();
$rows = $query
->fetchAll();
foreach ($rows as $res) {
$message = '<strong>' . $log_levels[$res->severity] . '</strong> <em>' . \Drupal::service('date.formatter')
->format($res->timestamp, 'long') . '</em> ' . $this
->formatMessage($res)
->render();
$current_row['log_messages']['#items'][]['#markup'] = $message;
}
$intent = new PushIntent($info
->getFlow(), $info
->getPool(), PushIntent::PUSH_FORCED, SyncIntent::ACTION_CREATE, $entity);
$intent
->execute(true);
$serialized = $intent
->getOperation()
->getData();
foreach ($serialized['embed_entities'] as $child) {
$id = $child[Entity::ENTITY_TYPE_KEY] . $child[Entity::UUID_KEY];
if (isset($children[$id])) {
continue;
}
$children[$id] = $child;
}
$result[] = $current_row;
}
$result[0]['label']['#attributes']['rowspan'] = $index + 1;
$result[0]['entity_type']['#attributes']['rowspan'] = $index + 1;
$result[0]['bundle']['#attributes']['rowspan'] = $index + 1;
$result[0]['id']['#attributes']['rowspan'] = $index + 1;
$result[0]['uuid']['#attributes']['rowspan'] = $index + 1;
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
$parent_entities[] = $entity;
foreach ($children as $child) {
$child_entity = $entity_repository
->loadEntityByUuid($child[Entity::ENTITY_TYPE_KEY], $child[Entity::UUID_KEY]);
$this
->debugEntity($result, $child_entity, $parent_entities);
}
}