flattenConfigObjects example


  public static function create($extension, array $config_objects) {
    $message = new FormattableMarkup('Configuration objects (@config_names) provided by @extension already exist in active configuration',
      [
        '@config_names' => implode(', ', static::flattenConfigObjects($config_objects)),
        '@extension' => $extension,
      ]
    );
    $e = new static($message);
    $e->configObjects = $config_objects;
    $e->extension = $extension;
    return $e;
  }

  /** * Flattens the config object array to a single dimensional list. * * @param array $config_objects * A list of configuration objects that already exist in active * configuration, keyed by config collection. * * @return array * A list of configuration objects that have been prefixed with their * collection. */

  protected function modulesFailToEnableMessage(array $modules, PreExistingConfigException $exception): PluralTranslatableMarkup {
    $config_objects = $exception->flattenConfigObjects($exception->getConfigObjects());
    return $this->formatPlural(
      count($config_objects),
      'Unable to install @extension, %config_names already exists in active configuration.',
      'Unable to install @extension, %config_names already exist in active configuration.',
      [
        '%config_names' => implode(', ', $config_objects),
        '@extension' => $modules['install'][$exception->getExtension()],
      ]);
  }

}
try {
        if ($this->themeInstaller->install([$theme])) {
          $themes = $this->themeHandler->listInfo();
          $this->messenger()->addStatus($this->t('The %theme theme has been installed.', ['%theme' => $themes[$theme]->info['name']]));
        }
        else {
          $this->messenger()->addError($this->t('The %theme theme was not found.', ['%theme' => $theme]));
        }
      }
      catch (PreExistingConfigException $e) {
        $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
        $this->messenger()->addError(
          $this->formatPlural(
            count($config_objects),
            'Unable to install @extension, %config_names already exists in active configuration.',
            'Unable to install @extension, %config_names already exist in active configuration.',
            [
              '%config_names' => implode(', ', $config_objects),
              '@extension' => $theme,
            ])
        );
      }
      

        }
        else {
          $this->messenger()->addStatus($this->t('The %theme theme has been installed.', ['%theme' => $themes[$theme]->info['name']]));
        }
      }
      else {
        $this->messenger()->addError($this->t('The %theme theme was not found.', ['%theme' => $theme]));
      }
    }
    catch (PreExistingConfigException $e) {
      $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
      $this->messenger()->addError(
        $this->formatPlural(
          count($config_objects),
          'Unable to install @extension, %config_names already exists in active configuration.',
          'Unable to install @extension, %config_names already exist in active configuration.',
          [
            '%config_names' => implode(', ', $config_objects),
            '@extension' => $theme,
          ])
      );
    }
    
Home | Imprint | This part of the site doesn't use cookies.