You are here

public function DebugForm::buildForm in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Form/DebugForm.php \Drupal\cms_content_sync\Form\DebugForm::buildForm()
  2. 2.0.x src/Form/DebugForm.php \Drupal\cms_content_sync\Form\DebugForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/DebugForm.php, line 158

Class

DebugForm
Content Sync advanced debug form.

Namespace

Drupal\cms_content_sync\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#tree'] = true;
  $settings = ContentSyncSettings::getInstance();
  $form['cms_content_sync_login'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Login at Sync Core'),
  ];

  // The extended entity export/import logging is stored within the key value table
  // since we do not want this stored within the Drupal configuration.
  $form['cms_content_sync_extended_entity_export_logging'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Extended Entity Export logging'),
    '#default_value' => $settings
      ->getExtendedEntityExportLogging() ?? 0,
    '#description' => $this
      ->t('When the "Extended Entity Export logging" is enabled, Content Sync is going to add a log entry to Watchdog
                                        showing all entity values processed by content sync after the <b><u>export</u></b>. This is helpful to debug outgoing entities.<br>
                                        <b>This will create many large log messages, so only use this for a short period of time and disable it immediately after your debugging session.</b>'),
  ];
  $form['cms_content_sync_extended_entity_import_logging'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Extended Entity Import logging'),
    '#default_value' => $settings
      ->getExtendedEntityImportLogging() ?? 0,
    '#description' => $this
      ->t('When the "Extended Entity Import logging" is enabled, Content Sync is going to add a log entry to Watchdog
                                        showing all entity values processed by content sync after the <b><u>import</u></b>. This is helpful to identify if an entity
                                        has changed after content sync has processed it.<br>
                                        <b>This will create many large log messages, so only use this for a short period of time and disable it immediately after your debugging session.</b>'),
  ];
  $form['cms_content_sync_inspect_entity'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Inspect entity'),
  ];
  $entity_types = $this->entityTypeManager
    ->getDefinitions();
  $field_map = $this->entityFieldManager
    ->getFieldMap();
  $entity_types_names = [];
  foreach ($entity_types as $type_key => $entity_type) {

    // This entity type doesn't contain any fields.
    if (!isset($field_map[$type_key])) {
      continue;
    }
    if ('cms_content_sync' == $entity_type
      ->getProvider()) {
      continue;
    }
    $entity_types_names[$type_key] = $type_key;
  }
  $form['cms_content_sync_inspect_entity']['entity_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Entity type'),
    '#options' => $entity_types_names,
    '#default_value' => 'node',
  ];
  $form['cms_content_sync_inspect_entity']['entity_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Entity ID'),
  ];
  $form['cms_content_sync_inspect_entity']['submit'] = [
    '#type' => 'button',
    '#value' => $this
      ->t('Check'),
    '#ajax' => [
      'callback' => '::inspectEntity',
      'wrapper' => 'cms_content_sync-inspect-entity-output',
    ],
  ];
  $form['cms_content_sync_inspect_entity']['entity'] = [
    '#prefix' => '<div class="cms_content_sync-inspect-entity-output">',
    '#suffix' => '</div>',
  ];
  $form['cms_content_sync_inspect_entity']['entity_data'] = [
    '#prefix' => '<div class="cms_content_sync-inspect-entity-data-output">',
    '#suffix' => '</div>',
  ];
  return parent::buildForm($form, $form_state);
}