src/Controller/ConfigInspectorController.php | 30 +++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Controller/ConfigInspectorController.php b/src/Controller/ConfigInspectorController.php index 24fc894..5d5f728 100644 --- a/src/Controller/ConfigInspectorController.php +++ b/src/Controller/ConfigInspectorController.php @@ -3,6 +3,7 @@ namespace Drupal\config_inspector\Controller; use Drupal\config_inspector\ConfigInspectorManager; +use Drupal\config_inspector\ConfigSchemaValidatability; use Drupal\Core\Config\Schema\ArrayElement; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Controller\ControllerBase; @@ -133,6 +134,7 @@ class ConfigInspectorController extends ControllerBase { '#header' => [ 'name' => $this->t('Configuration key'), 'schema' => $this->t('Schema'), + 'validatability' => $this->t('Validatable'), 'violations' => $this->t('Data'), 'list' => $this->t('List'), 'tree' => $this->t('Tree'), @@ -170,6 +172,7 @@ class ConfigInspectorController extends ControllerBase { $schema = $this->t('Correct'); $result = $this->configInspectorManager->checkValues($name); $raw_violations = $this->configInspectorManager->validateValues($name); + $raw_validatability = $this->configInspectorManager->checkValidatabilityValues($name); if (is_array($result)) { // The no-schema case is covered above already, if we got errors, the // schema is partial. @@ -183,6 +186,11 @@ class ConfigInspectorController extends ControllerBase { 'data-has-errors' => is_array($result), ], ], + 'validatability' => [ + '#markup' => $raw_validatability->isComplete() + ? $this->t('Validatable') + : $this->t('@validatability%', ['@validatability' => intval($raw_validatability->computePercentage() * 100)]), + ], 'violations' => [ '#markup' => $raw_violations->count() === 0 ? $this->t('Valid') @@ -243,7 +251,8 @@ class ConfigInspectorController extends ControllerBase { */ public function getTree($name) { $config_schema = $this->configInspectorManager->getConfigSchema($name); - $output = $this->formatTree($config_schema); + $validatability = $this->configInspectorManager->checkValidatabilityValues($name); + $output = $this->formatTree($config_schema, $validatability); $output['#title'] = $this->t('Tree of configuration data for %name', ['%name' => $name]); return $output; } @@ -329,6 +338,8 @@ class ConfigInspectorController extends ControllerBase { $rows = []; // Check compliance with the underlying primitives (string, boolean …). $errors = (array) $this->configInspectorManager->checkValues($config_name); + // Check validatability (beyond primitives). + $raw_validatability = $this->configInspectorManager->checkValidatabilityValues($config_name); // Check compliance with the validation constraints, if any. $raw_violations = $this->configInspectorManager->validateValues($config_name); $violations = ConfigInspectorManager::violationsToArray($raw_violations); @@ -343,6 +354,9 @@ class ConfigInspectorController extends ControllerBase { $key, $definition['label'], $definition['type'], + $raw_validatability->getValidatabilityPerPropertyPath()[$key] + ? $this->t('Yes') + : $this->t('No'), $this->formatValue($element), @$errors[$config_name . ':' . $key] ?: '', !array_key_exists($key, $violations) @@ -362,6 +376,7 @@ class ConfigInspectorController extends ControllerBase { $this->t('Name'), $this->t('Label'), $this->t('Type'), + $this->t('Validatable'), $this->t('Value'), $this->t('Error'), $this->t('Validation error'), @@ -375,6 +390,8 @@ class ConfigInspectorController extends ControllerBase { * * @param array|object $schema * The schema. + * @param \Drupal\config_inspector\ConfigSchemaValidatability $validatability + * The associated validatability. * @param bool $collapsed * (Optional) Indicates whether the details are collapsed by default. * @param string $base_key @@ -383,28 +400,31 @@ class ConfigInspectorController extends ControllerBase { * @return array * The tree in the form of a render array. */ - public function formatTree($schema, $collapsed = FALSE, $base_key = '') { + public function formatTree($schema, ConfigSchemaValidatability $validatability, $collapsed = FALSE, $base_key = '') { $build = []; foreach ($schema as $key => $element) { $definition = $element->getDataDefinition(); $label = $definition['label'] ?: $this->t('N/A'); $type = $definition['type']; $element_key = $base_key . $key; + $is_validatable = $validatability->getValidatabilityPerPropertyPath()[$base_key . $key] + ? $this->t('validatable') + : '' . $this->t('validatable') . ''; if ($element instanceof ArrayElement) { $build[$key] = [ '#type' => 'details', '#title' => $label, - '#description' => $element_key . ' (' . $type . ')', + '#description' => $element_key . ' (' . $type . ', ' . $is_validatable . ')', '#description_display' => 'after', '#open' => !$collapsed, - ] + $this->formatTree($element, TRUE, $element_key . '.'); + ] + $this->formatTree($element, $validatability, TRUE, $element_key . '.'); } else { $build[$key] = [ '#type' => 'item', '#title' => $label, '#plain_text' => $this->formatValue($element), - '#description' => $element_key . ' (' . $type . ')', + '#description' => $element_key . ' (' . $type . ', ' . $is_validatable . ')', '#description_display' => 'after', ]; }