public function DebugForm::inspectEntity in CMS Content Sync 2.0.x
Same name and namespace in other branches
- 8 src/Form/DebugForm.php \Drupal\cms_content_sync\Form\DebugForm::inspectEntity()
- 2.1.x src/Form/DebugForm.php \Drupal\cms_content_sync\Form\DebugForm::inspectEntity()
Display debug output for a given entity to analyze it's sync structure.
Parameters
array $form:
Return value
AjaxResponse|array The debug output table
File
- src/
Form/ DebugForm.php, line 98
Class
- DebugForm
- Content Sync advanced debug form.
Namespace
Drupal\cms_content_sync\FormCode
public function inspectEntity($form, FormStateInterface $form_state) {
$entity_type = $form_state
->getValue([
'cms_content_sync_inspect_entity',
'entity_type',
]);
$entity_id = $form_state
->getValue([
'cms_content_sync_inspect_entity',
'entity_id',
]);
$result = [];
if ($entity_type && $entity_id) {
$storage = $this->entityTypeManager
->getStorage($entity_type);
$entity = $storage
->load($entity_id);
if (!$entity) {
$form_state
->setError($form['cms_content_sync_inspect_entity']['entity_id'], 'This entity doesn\'t exist.');
return $result;
}
}
$ajax_response = new AjaxResponse();
if ($entity) {
$result = [
'#type' => 'table',
'#sticky' => true,
'#header' => array_merge([
$this
->t('Label'),
$this
->t('Entity Type'),
$this
->t('Bundle'),
$this
->t('ID'),
$this
->t('UUID'),
$this
->t('Entity Status ID'),
$this
->t('Flow'),
$this
->t('Pool'),
$this
->t('Flags'),
$this
->t('Last push / edit date'),
$this
->t('Last pull'),
$this
->t('Latest log messages'),
]),
];
$this
->debugEntity($result, $entity);
$ajax_response
->addCommand(new HtmlCommand('.cms_content_sync-inspect-entity-output', $result));
$serializer = \Drupal::service('serializer');
$data = $serializer
->serialize($entity, 'json', [
'plugin_id' => 'entity',
]);
$entity_data = '<b>Entity Data:</b><br>';
$entity_data .= '<br><pre><code>' . $data . '</code></pre>';
$ajax_response
->addCommand(new HtmlCommand('.cms_content_sync-inspect-entity-data-output', $entity_data));
}
return $ajax_response;
}