/** * {@inheritdoc} */ public function updateExtension($type, $name, array $changelist = array(), $safe_only = TRUE) { // If no change list was passed, load one. if (empty($changelist)) { $changelist = $this->configSyncLister->getExtensionChangelist($type, $name, $safe_only); } // Process create changes. if (!empty($changelist['create'])) { foreach ($changelist['create'] as $item_name) { if (!($entity_type = $this->configManager->getEntityTypeIdByName($name))) { $entity_type = 'system.simple'; } $this->configRevert->import($entity_type, $item_name); } } // Process update changes. if (!empty($changelist['update'])) { foreach ($changelist['update'] as $item_name) { if (!($entity_type = $this->configManager->getEntityTypeIdByName($name))) { $entity_type = 'system.simple'; } $this->configRevert->revert($entity_type, $item_name); } } // Refresh the configuration snapshot. $this->configSyncSnapshotter->createExtensionSnapshot($type, $name); }
/** * 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; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->assigner->assignConfigPackages(); $config = $this->featuresManager->getConfigCollection(); $items = array_filter($form_state->getValue('diff')); if (empty($items)) { drupal_set_message('No configuration was selected for import.', 'warning'); return; } foreach ($items as $config_name) { if (isset($config[$config_name])) { $item = $config[$config_name]; $this->configRevert->revert($item['type'], $item['name_short']); } else { $item = $this->featuresManager->getConfigType($config_name); $this->configRevert->import($item['type'], $item['name_short']); } drupal_set_message(t('Imported !name', array('!name' => $config_name))); } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->configRevert->revert($this->type, $this->name); drupal_set_message($this->t('The configuration was reverted to its source.')); $form_state->setRedirectUrl($this->getCancelUrl()); }
/** * Imports the configuration missing from the active store */ protected function importMissing() { $config = $this->featuresManager->getConfigCollection(); $missing = $this->featuresManager->reorderMissing($this->missing); foreach ($missing as $config_name) { if (!isset($config[$config_name])) { $item = $this->featuresManager->getConfigType($config_name); $type = ConfigurationItem::fromConfigStringToConfigType($item['type']); try { $this->configRevert->import($type, $item['name_short']); drupal_set_message($this->t('Imported @name', array('@name' => $config_name))); } catch (\Exception $e) { drupal_set_message($this->t('Error importing @name : @message', array('@name' => $config_name, '@message' => $e->getMessage())), 'error'); } } } }