// Attempt to import configuration and verify that an error message appears
// and the node type, body field and entity displays are still scheduled for
// removal.
$this->submitForm([], 'Import all'); $validation_message = "Entities exist of type {$node->getEntityType()->getLabel()} and {$node->getEntityType()->getBundleLabel()} {$node_type->label()}. These entities need to be deleted before importing."; $this->assertSession()->pageTextContains($validation_message); $this->assertSession()->pageTextContains('node.type.' . $node_type->id()); $this->assertSession()->pageTextContains('field.field.node.' . $node_type->id() . '.body'); $this->assertSession()->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.teaser'); $this->assertSession()->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.default'); $this->assertSession()->pageTextContains('core.entity_form_display.node.' . $node_type->id() . '.default');
// If the entity has bundles, allow option to restrict to bundle(s).
if($entity_type->hasKey('bundle')){ $bundle_options = []; foreach($this->entityTypeBundleInfo->getBundleInfo($entity_type_id)as$bundle_id => $bundle_info){ $bundle_options[$bundle_id] = $bundle_info['label']; }
$form['bundles'] = [ '#title' => $entity_type->getBundleLabel() ?: $this->t('Bundles'), '#default_value' => $this->options['bundles'], '#type' => 'checkboxes', '#options' => $bundle_options, '#description' => $this->t('If none are selected, all are allowed.'), ]; }
// Offer the option to filter by access to the entity in the argument.
$form['access'] = [ '#type' => 'checkbox', '#title' => $this->t('Validate user has access to the %name', ['%name' => $entity_type->getLabel()]),
$info['placeholder'] = $this->t('Enter field or @bundle', ['@bundle' => $bundle]); $info['description'] = $this->t('Enter a part of the field or @bundle to filter by.', ['@bundle' => $bundle]);
return$info; }
/**
* {@inheritdoc}
*/
if($bundle_of = $entity_type->getBundleOf()){ // Work out if there are entities with this bundle.
$bundle_of_entity_type = $this->entityTypeManager->getDefinition($bundle_of); $bundle_id = ConfigEntityStorage::getIDFromConfigName($config_name, $entity_type->getConfigPrefix()); $entity_query = $this->entityTypeManager->getStorage($bundle_of)->getQuery(); $entity_ids = $entity_query->condition($bundle_of_entity_type->getKey('bundle'), $bundle_id) ->accessCheck(FALSE) ->range(0, 1) ->execute(); if(!empty($entity_ids)){ $entity = $this->entityTypeManager->getStorage($entity_type_id)->load($bundle_id); $event->getConfigImporter()->logError($this->t('Entities exist of type %entity_type and %bundle_label %bundle. These entities need to be deleted before importing.', ['%entity_type' => $bundle_of_entity_type->getLabel(), '%bundle_label' => $bundle_of_entity_type->getBundleLabel(), '%bundle' => $entity->label()])); } } } } }
if(isset($originalRevisionTimestamp)){ $date = $this->dateFormatter->format($originalRevisionTimestamp); $this->messenger->addMessage($this->t('@type %title has been reverted to the revision from %revision-date.', [ '@type' => $bundleLabel, '%title' => $revisionLabel,