本文整理汇总了PHP中Drupal::entityDefinitionUpdateManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::entityDefinitionUpdateManager方法的具体用法?PHP Drupal::entityDefinitionUpdateManager怎么用?PHP Drupal::entityDefinitionUpdateManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal
的用法示例。
在下文中一共展示了Drupal::entityDefinitionUpdateManager方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInstaller
/**
* Ensures that the user page is available after installation.
*/
public function testInstaller()
{
// Do assertions from parent.
parent::testInstaller();
// Do assertions specific to test.
$this->assertEqual(drupal_realpath($this->sync_dir), config_get_config_directory(CONFIG_SYNC_DIRECTORY), 'The sync directory has been updated during the installation.');
$this->assertEqual(USER_REGISTER_ADMINISTRATORS_ONLY, \Drupal::config('user.settings')->get('register'), 'Ensure standard_install() does not overwrite user.settings::register.');
$this->assertEqual([], \Drupal::entityDefinitionUpdateManager()->getChangeSummary(), 'There are no entity or field definition updates.');
}
示例2: testAddingFields
/**
* Tests that email token in status_blocked of user.mail is updated.
*/
public function testAddingFields()
{
$this->runUpdates();
$post_revision_created = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('revision_created', 'block_content');
$post_revision_user = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('revision_user', 'block_content');
$this->assertTrue($post_revision_created instanceof BaseFieldDefinition, "Revision created field found");
$this->assertTrue($post_revision_user instanceof BaseFieldDefinition, "Revision user field found");
$this->assertEqual('created', $post_revision_created->getType(), "Field is type created");
$this->assertEqual('entity_reference', $post_revision_user->getType(), "Field is type entity_reference");
}
示例3: uninstall
/**
* {@inheritdoc}
*/
public function uninstall(array $module_list, $uninstall_dependents = TRUE)
{
// Get all module data so we can find dependencies and sort.
$module_data = system_rebuild_module_data();
$module_list = $module_list ? array_combine($module_list, $module_list) : array();
if (array_diff_key($module_list, $module_data)) {
// One or more of the given modules doesn't exist.
return FALSE;
}
$extension_config = \Drupal::configFactory()->getEditable('core.extension');
$installed_modules = $extension_config->get('module') ?: array();
if (!($module_list = array_intersect_key($module_list, $installed_modules))) {
// Nothing to do. All modules already uninstalled.
return TRUE;
}
if ($uninstall_dependents) {
// Add dependent modules to the list. The new modules will be processed as
// the while loop continues.
$profile = drupal_get_profile();
while (list($module) = each($module_list)) {
foreach (array_keys($module_data[$module]->required_by) as $dependent) {
if (!isset($module_data[$dependent])) {
// The dependent module does not exist.
return FALSE;
}
// Skip already uninstalled modules.
if (isset($installed_modules[$dependent]) && !isset($module_list[$dependent]) && $dependent != $profile) {
$module_list[$dependent] = $dependent;
}
}
}
}
// Use the validators and throw an exception with the reasons.
if ($reasons = $this->validateUninstall($module_list)) {
foreach ($reasons as $reason) {
$reason_message[] = implode(', ', $reason);
}
throw new ModuleUninstallValidatorException('The following reasons prevent the modules from being uninstalled: ' . implode('; ', $reason_message));
}
// Set the actual module weights.
$module_list = array_map(function ($module) use($module_data) {
return $module_data[$module]->sort;
}, $module_list);
// Sort the module list by their weights.
asort($module_list);
$module_list = array_keys($module_list);
// Only process modules that are enabled. A module is only enabled if it is
// configured as enabled. Custom or overridden module handlers might contain
// the module already, which means that it might be loaded, but not
// necessarily installed.
foreach ($module_list as $module) {
// Clean up all entity bundles (including fields) of every entity type
// provided by the module that is being uninstalled.
// @todo Clean this up in https://www.drupal.org/node/2350111.
$entity_manager = \Drupal::entityManager();
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->getProvider() == $module) {
foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) {
$entity_manager->onBundleDelete($bundle, $entity_type_id);
}
}
}
// Allow modules to react prior to the uninstallation of a module.
$this->moduleHandler->invokeAll('module_preuninstall', array($module));
// Uninstall the module.
module_load_install($module);
$this->moduleHandler->invoke($module, 'uninstall');
// Remove all configuration belonging to the module.
\Drupal::service('config.manager')->uninstall('module', $module);
// In order to make uninstalling transactional if anything uses routes.
\Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider'));
\Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder'));
// Notify interested components that this module's entity types are being
// deleted. For example, a SQL-based storage handler can use this as an
// opportunity to drop the corresponding database tables.
// @todo Clean this up in https://www.drupal.org/node/2350111.
$update_manager = \Drupal::entityDefinitionUpdateManager();
foreach ($entity_manager->getDefinitions() as $entity_type) {
if ($entity_type->getProvider() == $module) {
$update_manager->uninstallEntityType($entity_type);
} elseif ($entity_type->isSubclassOf(FieldableEntityInterface::CLASS)) {
// The module being installed may be adding new fields to existing
// entity types. Field definitions for any entity type defined by
// the module are handled in the if branch.
$entity_type_id = $entity_type->id();
/** @var \Drupal\Core\Entity\FieldableEntityStorageInterface $storage */
$storage = $entity_manager->getStorage($entity_type_id);
foreach ($entity_manager->getFieldStorageDefinitions($entity_type_id) as $storage_definition) {
// @todo We need to trigger field purging here.
// See https://www.drupal.org/node/2282119.
if ($storage_definition->getProvider() == $module && !$storage->countFieldData($storage_definition, TRUE)) {
$update_manager->uninstallFieldStorageDefinition($storage_definition);
}
}
}
}
// Remove the schema.
//.........这里部分代码省略.........
示例4: testMultiColumnNonRevisionableBaseField
/**
* Tests multi column non revisionable base field for revisionable entity.
*/
public function testMultiColumnNonRevisionableBaseField()
{
\Drupal::state()->set('entity_test.multi_column', TRUE);
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
// Refresh the storage.
$this->mulRev = $this->entityManager->getStorage('entity_test_mulrev');
$user1 = $this->createUser();
// Create a test entity.
$entity = EntityTestMulRev::create(['name' => $this->randomString(), 'user_id' => $user1->id(), 'language' => 'en', 'non_rev_field' => 'Huron', 'description' => ['shape' => 'shape', 'color' => 'color']]);
$entity->save();
$entity = $this->mulRev->loadUnchanged($entity->id());
$expected = [['shape' => 'shape', 'color' => 'color']];
$this->assertEquals('Huron', $entity->get('non_rev_field')->value, 'Huron found on entity 1');
$this->assertEquals($expected, $entity->description->getValue());
}
示例5: runUpdates
/**
* Helper function to run pending database updates.
*/
protected function runUpdates()
{
if (!$this->zlibInstalled) {
$this->fail('Missing zlib requirement for update tests.');
return FALSE;
}
// The site might be broken at the time so logging in using the UI might
// not work, so we use the API itself.
drupal_rewrite_settings(['settings' => ['update_free_access' => (object) ['value' => TRUE, 'required' => TRUE]]]);
$this->drupalGet($this->updateUrl);
$this->clickLink(t('Continue'));
$this->doSelectionTest();
// Run the update hooks.
$this->clickLink(t('Apply pending updates'));
// Ensure there are no failed updates.
if ($this->checkFailedUpdates) {
$this->assertNoRaw('<strong>' . t('Failed:') . '</strong>');
// The config schema can be incorrect while the update functions are being
// executed. But once the update has been completed, it needs to be valid
// again. Assert the schema of all configuration objects now.
$names = $this->container->get('config.storage')->listAll();
/** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
$typed_config = $this->container->get('config.typed');
$typed_config->clearCachedDefinitions();
foreach ($names as $name) {
$config = $this->config($name);
$this->assertConfigSchema($typed_config, $name, $config->get());
}
// Ensure that the update hooks updated all entity schema.
$needs_updates = \Drupal::entityDefinitionUpdateManager()->needsUpdates();
$this->assertFalse($needs_updates, 'After all updates ran, entity schema is up to date.');
if ($needs_updates) {
foreach (\Drupal::entityDefinitionUpdateManager()->getChangeSummary() as $entity_type_id => $summary) {
foreach ($summary as $message) {
$this->fail($message);
}
}
}
}
}