当前位置: 首页>>代码示例>>PHP>>正文


PHP ConfigImporter::validate方法代码示例

本文整理汇总了PHP中Drupal\Core\Config\ConfigImporter::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigImporter::validate方法的具体用法?PHP ConfigImporter::validate怎么用?PHP ConfigImporter::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Config\ConfigImporter的用法示例。


在下文中一共展示了ConfigImporter::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: configImport

 private function configImport($io, StorageComparer $storage_comparer)
 {
     $config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.manager'), \Drupal::lock(), \Drupal::service('config.typed'), \Drupal::moduleHandler(), \Drupal::service('module_installer'), \Drupal::service('theme_handler'), \Drupal::service('string_translation'));
     if ($config_importer->alreadyImporting()) {
         $io->success($this->trans('commands.config.import.messages.already-imported'));
     } else {
         try {
             if ($config_importer->validate()) {
                 $sync_steps = $config_importer->initialize();
                 foreach ($sync_steps as $step) {
                     $context = array();
                     do {
                         $config_importer->doSyncStep($step, $context);
                     } while ($context['finished'] < 1);
                 }
             }
         } catch (ConfigImporterException $e) {
             $message = 'The import failed due for the following reasons:' . "\n";
             $message .= implode("\n", $config_importer->getErrors());
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $message));
         } catch (\Exception $e) {
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $e->getMessage()));
         }
     }
 }
开发者ID:jeyram,项目名称:DrupalConsole,代码行数:25,代码来源:ImportSingleCommand.php

示例2: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // The confirmation step needs no additional validation.
     if ($this->data) {
         return;
     }
     // Decode the submitted import.
     $data = Yaml::decode($form_state->getValue('import'));
     // Validate for config entities.
     if ($form_state->getValue('config_type') !== 'system.simple') {
         $definition = $this->entityManager->getDefinition($form_state->getValue('config_type'));
         $id_key = $definition->getKey('id');
         // If a custom entity ID is specified, override the value in the
         // configuration data being imported.
         if (!$form_state->isValueEmpty('custom_entity_id')) {
             $data[$id_key] = $form_state->getValue('custom_entity_id');
         }
         $entity_storage = $this->entityManager->getStorage($form_state->getValue('config_type'));
         // If an entity ID was not specified, set an error.
         if (!isset($data[$id_key])) {
             $form_state->setErrorByName('import', $this->t('Missing ID key "@id_key" for this @entity_type import.', array('@id_key' => $id_key, '@entity_type' => $definition->getLabel())));
             return;
         }
         $config_name = $definition->getConfigPrefix() . '.' . $data[$id_key];
         // If there is an existing entity, ensure matching ID and UUID.
         if ($entity = $entity_storage->load($data[$id_key])) {
             $this->configExists = $entity;
             if (!isset($data['uuid'])) {
                 $form_state->setErrorByName('import', $this->t('An entity with this machine name already exists but the import did not specify a UUID.'));
                 return;
             }
             if ($data['uuid'] !== $entity->uuid()) {
                 $form_state->setErrorByName('import', $this->t('An entity with this machine name already exists but the UUID does not match.'));
                 return;
             }
         } elseif (isset($data['uuid']) && $entity_storage->loadByProperties(array('uuid' => $data['uuid']))) {
             $form_state->setErrorByName('import', $this->t('An entity with this UUID already exists but the machine name does not match.'));
         }
     } else {
         $config_name = $form_state->getValue('config_name');
         $config = $this->config($config_name);
         $this->configExists = !$config->isNew() ? $config : FALSE;
     }
     // Use ConfigImporter validation.
     if (!$form_state->getErrors()) {
         $source_storage = new StorageReplaceDataWrapper($this->configStorage);
         $source_storage->replaceData($config_name, $data);
         $storage_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager);
         if (!$storage_comparer->createChangelist()->hasChanges()) {
             $form_state->setErrorByName('import', $this->t('There are no changes to import.'));
         } else {
             $config_importer = new ConfigImporter($storage_comparer, $this->eventDispatcher, $this->configManager, $this->lock, $this->typedConfigManager, $this->moduleHandler, $this->moduleInstaller, $this->themeHandler, $this->getStringTranslation());
             try {
                 $config_importer->validate();
                 $form_state->set('config_importer', $config_importer);
             } catch (ConfigImporterException $e) {
                 // There are validation errors.
                 $item_list = ['#theme' => 'item_list', '#items' => $config_importer->getErrors(), '#title' => $this->t('The configuration cannot be imported because it failed validation for the following reasons:')];
                 $form_state->setErrorByName('import', $this->renderer->render($item_list));
             }
         }
     }
     // Store the decoded version of the submitted import.
     $form_state->setValueForElement($form['import'], $data);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:68,代码来源:ConfigSingleImportForm.php


注:本文中的Drupal\Core\Config\ConfigImporter::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。