/**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state) {
   $value = $this->configRevert->getFromExtension($this->type, $this->name);
   if (!$value) {
     $form_state->setErrorByName('', $this->t('There is no configuration @type named @name to import', array('@type' => $this->type, '@name' => $this->name)));
     return;
   }
 }
Ejemplo n.º 2
0
 /**
  * Builds a table for the report.
  *
  * @param string[] $names
  *   List of machine names of config items for the table.
  * @param string $storage
  *   Config storage the items can be loaded from, either 'active' or
  *   'extension'.
  * @param string[] $actions
  *   Action links to include, one or more of:
  *   - diff
  *   - revert
  *   - export
  *   - import
  *   - delete
  *
  * @return array
  *   Render array for the table, not including the #empty and #prefix
  *   properties.
  */
 protected function makeReportTable($names, $storage, $actions)
 {
     $build = array();
     $build['#type'] = 'table';
     $build['#attributes'] = array('class' => array('config-update-report'));
     $build['#header'] = array('name' => array('data' => $this->t('Machine name')), 'label' => array('data' => $this->t('Label (if any)'), 'class' => array(RESPONSIVE_PRIORITY_LOW)), 'type' => array('data' => $this->t('Type'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), 'operations' => array('data' => $this->t('Operations')));
     $build['#rows'] = array();
     foreach ($names as $name) {
         $row = array();
         if ($storage == 'active') {
             $config = $this->configRevert->getFromActive('', $name);
         } else {
             $config = $this->configRevert->getFromExtension('', $name);
         }
         // Figure out what type of config it is, and get the ID.
         $entity_type = $this->configList->getTypeNameByConfigName($name);
         if (!$entity_type) {
             // This is simple config.
             $id = $name;
             $type_label = $this->t('Simple configuration');
             $entity_type = 'system.simple';
         } else {
             $definition = $this->configList->getType($entity_type);
             $id_key = $definition->getKey('id');
             $id = $config[$id_key];
             $type_label = $definition->getLabel();
         }
         $label = isset($config['label']) ? $config['label'] : '';
         $row[] = $name;
         $row[] = $label;
         $row[] = $type_label;
         $links = array();
         $routes = array('export' => 'config.export_single', 'import' => 'config_update_ui.import', 'diff' => 'config_update_ui.diff', 'revert' => 'config_update_ui.revert', 'delete' => 'config_update_ui.delete');
         $titles = array('export' => $this->t('Export'), 'import' => $this->t('Import from source'), 'diff' => $this->t('Show differences'), 'revert' => $this->t('Revert to source'), 'delete' => $this->t('Delete'));
         foreach ($actions as $action) {
             $links[$action] = array('url' => Url::fromRoute($routes[$action], array('config_type' => $entity_type, 'config_name' => $id)), 'title' => $titles[$action]);
         }
         $row[] = array('data' => array('#type' => 'operations', '#links' => $links));
         $build['#rows'][] = $row;
     }
     return $build;
 }