本文整理汇总了PHP中Drupal\block\Entity\Block::loadMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP Block::loadMultiple方法的具体用法?PHP Block::loadMultiple怎么用?PHP Block::loadMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\block\Entity\Block
的用法示例。
在下文中一共展示了Block::loadMultiple方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBlockMigration
/**
* Tests the block migration.
*/
public function testBlockMigration()
{
$blocks = Block::loadMultiple();
$this->assertIdentical(9, count($blocks));
// User blocks
$visibility = [];
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = TRUE;
$visibility['request_path']['pages'] = "<front>\n/node/1\n/blog/*";
$this->assertEntity('user', $visibility, 'sidebar_first', 'bartik', 0, '', '0');
$visibility = [];
$this->assertEntity('user_1', $visibility, 'sidebar_first', 'bartik', 0, '', '0');
$visibility['user_role']['id'] = 'user_role';
$roles['authenticated'] = 'authenticated';
$visibility['user_role']['roles'] = $roles;
$context_mapping['user'] = '@user.current_user_context:current_user';
$visibility['user_role']['context_mapping'] = $context_mapping;
$visibility['user_role']['negate'] = FALSE;
$this->assertEntity('user_2', $visibility, 'sidebar_second', 'bartik', -9, '', '0');
$visibility = [];
$visibility['user_role']['id'] = 'user_role';
$visibility['user_role']['roles'] = ['migrate_test_role_1' => 'migrate_test_role_1'];
$context_mapping['user'] = '@user.current_user_context:current_user';
$visibility['user_role']['context_mapping'] = $context_mapping;
$visibility['user_role']['negate'] = FALSE;
$this->assertEntity('user_3', $visibility, 'sidebar_second', 'bartik', -6, '', '0');
// Check system block
$visibility = [];
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = TRUE;
$visibility['request_path']['pages'] = '/node/1';
$this->assertEntity('system', $visibility, 'footer_fifth', 'bartik', -5, '', '0');
// Check menu blocks
$visibility = [];
$this->assertEntity('menu', $visibility, 'header', 'bartik', -5, '', '0');
// Check custom blocks
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = FALSE;
$visibility['request_path']['pages'] = '<front>';
$this->assertEntity('block', $visibility, 'content', 'bartik', 0, 'Static Block', 'visible');
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = FALSE;
$visibility['request_path']['pages'] = '/node';
// bluemarine does not exist in Drupal 8 and the d6_block migration defines
// no mapping for its regions, so this block should have been defaulted
// to the 'content' region.
$this->assertEntity('block_1', $visibility, 'content', 'bluemarine', -4, 'Another Static Block', 'visible');
$visibility = [];
$this->assertEntity('block_2', $visibility, 'right', 'test_theme', -7, '', '0');
// Custom block with php code is not migrated.
$block = Block::load('block_3');
$this->assertFalse($block instanceof Block);
}
示例2: testBlockMigration
/**
* Tests the block migration.
*/
public function testBlockMigration()
{
$blocks = Block::loadMultiple();
$this->assertIdentical(9, count($blocks));
// User blocks
$visibility = [];
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = TRUE;
$visibility['request_path']['pages'] = "<front>\n/node/1\n/blog/*";
$this->assertEntity('user', $visibility, 'sidebar_first', 'bartik', 0);
$visibility = [];
$this->assertEntity('user_1', $visibility, 'sidebar_first', 'bartik', 0);
$visibility['user_role']['id'] = 'user_role';
$roles['authenticated'] = 'authenticated';
$visibility['user_role']['roles'] = $roles;
$context_mapping['user'] = '@user.current_user_context:current_user';
$visibility['user_role']['context_mapping'] = $context_mapping;
$visibility['user_role']['negate'] = FALSE;
$this->assertEntity('user_2', $visibility, 'sidebar_second', 'bartik', -9);
$visibility = [];
$visibility['user_role']['id'] = 'user_role';
$visibility['user_role']['roles'] = ['migrate_test_role_1' => 'migrate_test_role_1'];
$context_mapping['user'] = '@user.current_user_context:current_user';
$visibility['user_role']['context_mapping'] = $context_mapping;
$visibility['user_role']['negate'] = FALSE;
$this->assertEntity('user_3', $visibility, 'sidebar_second', 'bartik', -6);
// Check system block
$visibility = [];
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = TRUE;
$visibility['request_path']['pages'] = '/node/1';
$this->assertEntity('system', $visibility, 'footer', 'bartik', -5);
// Check menu blocks
$visibility = [];
$this->assertEntity('menu', $visibility, 'header', 'bartik', -5);
// Check custom blocks
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = FALSE;
$visibility['request_path']['pages'] = '<front>';
$this->assertEntity('block', $visibility, 'content', 'bartik', 0);
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = FALSE;
$visibility['request_path']['pages'] = '/node';
$this->assertEntity('block_1', $visibility, 'sidebar_second', 'bluemarine', -4);
$visibility = [];
$this->assertEntity('block_2', $visibility, 'right', 'test_theme', -7);
// Custom block with php code is not migrated.
$block = Block::load('block_3');
$this->assertFalse($block instanceof Block);
}
示例3: testBlockMigration
/**
* Test the block settings migration.
*/
public function testBlockMigration()
{
$blocks = Block::loadMultiple();
$this->assertIdentical(count($blocks), 10);
// User blocks
$test_block_user = $blocks['user'];
$this->assertNotNull($test_block_user);
$this->assertIdentical('sidebar_first', $test_block_user->getRegion());
$this->assertIdentical('bartik', $test_block_user->getTheme());
$visibility = $test_block_user->getVisibility();
$this->assertTrue(empty($visibility));
$this->assertIdentical(0, $test_block_user->getWeight());
$test_block_user_1 = $blocks['user_1'];
$this->assertNotNull($test_block_user_1);
$this->assertIdentical('sidebar_first', $test_block_user_1->getRegion());
$this->assertIdentical('bartik', $test_block_user_1->getTheme());
$visibility = $test_block_user_1->getVisibility();
$this->assertTrue(empty($visibility));
$this->assertIdentical(0, $test_block_user_1->getWeight());
$test_block_user_2 = $blocks['user_2'];
$this->assertNotNull($test_block_user_2);
$this->assertIdentical('sidebar_second', $test_block_user_2->getRegion());
$this->assertIdentical('bartik', $test_block_user_2->getTheme());
$visibility = $test_block_user_2->getVisibility();
$this->assertIdentical($visibility['user_role']['id'], 'user_role');
$roles = array();
$roles['authenticated'] = 'authenticated';
$this->assertIdentical($visibility['user_role']['roles'], $roles);
$this->assertFalse($visibility['user_role']['negate']);
$this->assertIdentical(-9, $test_block_user_2->getWeight());
$test_block_user_3 = $blocks['user_3'];
$this->assertNotNull($test_block_user_3);
$this->assertIdentical('sidebar_second', $test_block_user_3->getRegion());
$this->assertIdentical('bartik', $test_block_user_3->getTheme());
$visibility = $test_block_user_3->getVisibility();
$this->assertIdentical($visibility['user_role']['id'], 'user_role');
$roles = array();
$roles['migrate_test_role_1'] = 'migrate_test_role_1';
$this->assertIdentical($visibility['user_role']['roles'], $roles);
$this->assertFalse($visibility['user_role']['negate']);
$this->assertIdentical(-6, $test_block_user_3->getWeight());
// Check system block
$test_block_system = $blocks['system'];
$this->assertNotNull($test_block_system);
$this->assertIdentical('footer', $test_block_system->getRegion());
$this->assertIdentical('bartik', $test_block_system->getTheme());
$visibility = $test_block_system->getVisibility();
$this->assertIdentical('request_path', $visibility['request_path']['id']);
$this->assertIdentical('node/1', $visibility['request_path']['pages']);
$this->assertTrue($visibility['request_path']['negate']);
$this->assertIdentical(-5, $test_block_system->getWeight());
// Check menu blocks
$test_block_menu = $blocks['menu'];
$this->assertNotNull($test_block_menu);
$this->assertIdentical('header', $test_block_menu->getRegion());
$this->assertIdentical('bartik', $test_block_menu->getTheme());
$visibility = $test_block_menu->getVisibility();
$this->assertTrue(empty($visibility));
$this->assertIdentical(-5, $test_block_menu->getWeight());
// Check custom blocks
$test_block_block = $blocks['block'];
$this->assertNotNull($test_block_block);
$this->assertIdentical('content', $test_block_block->getRegion());
$this->assertIdentical('bartik', $test_block_block->getTheme());
$visibility = $test_block_block->getVisibility();
$this->assertIdentical('request_path', $visibility['request_path']['id']);
$this->assertIdentical('<front>', $visibility['request_path']['pages']);
$this->assertFalse($visibility['request_path']['negate']);
$this->assertIdentical(0, $test_block_block->getWeight());
$test_block_block_1 = $blocks['block_1'];
$this->assertNotNull($test_block_block_1);
$this->assertIdentical('right', $test_block_block_1->getRegion());
$this->assertIdentical('bluemarine', $test_block_block_1->getTheme());
$visibility = $test_block_block_1->getVisibility();
$this->assertIdentical('request_path', $visibility['request_path']['id']);
$this->assertIdentical('node', $visibility['request_path']['pages']);
$this->assertFalse($visibility['request_path']['negate']);
$this->assertIdentical(-4, $test_block_block_1->getWeight());
$test_block_block_2 = $blocks['block_2'];
$this->assertNotNull($test_block_block_2);
$this->assertIdentical('right', $test_block_block_2->getRegion());
$this->assertIdentical('test_theme', $test_block_block_2->getTheme());
$visibility = $test_block_block_2->getVisibility();
$this->assertTrue(empty($visibility));
$this->assertIdentical(-7, $test_block_block_2->getWeight());
$test_block_block_3 = $blocks['block_3'];
$this->assertNotNull($test_block_block_3);
$this->assertIdentical('left', $test_block_block_3->getRegion());
$this->assertIdentical('test_theme', $test_block_block_3->getTheme());
$visibility = $test_block_block_3->getVisibility();
$this->assertTrue(empty($visibility));
$this->assertIdentical(-2, $test_block_block_3->getWeight());
}
示例4: testBlockMigration
/**
* Tests the block migration.
*/
public function testBlockMigration()
{
$this->assertEntity('bartik_system_main', 'system_main_block', [], '', 'content', 'bartik', 0, '', '0');
$this->assertEntity('bartik_search_form', 'search_form_block', [], '', 'sidebar_first', 'bartik', -1, '', '0');
$this->assertEntity('bartik_user_login', 'user_login_block', [], '', 'sidebar_first', 'bartik', 0, '', '0');
$this->assertEntity('bartik_system_powered-by', 'system_powered_by_block', [], '', 'footer', 'bartik', 10, '', '0');
$this->assertEntity('seven_system_main', 'system_main_block', [], '', 'content', 'seven', 0, '', '0');
$this->assertEntity('seven_user_login', 'user_login_block', [], '', 'content', 'seven', 10, '', '0');
// The d7_custom_block migration should have migrated a block containing a
// mildly amusing limerick. We'll need its UUID to determine
// bartik_block_1's plugin ID.
$uuid = BlockContent::load(1)->uuid();
$this->assertEntity('bartik_block_1', 'block_content:' . $uuid, ['authenticated'], '', 'highlighted', 'bartik', 0, 'Mildly amusing limerick of the day', 'visible');
// Assert that disabled blocks (or enabled blocks whose plugin IDs could
// be resolved) did not migrate.
$non_existent_blocks = ['bartik_system_navigation', 'bartik_system_help', 'seven_user_new', 'seven_search_form', 'bartik_comment_recent', 'bartik_node_syndicate', 'bartik_node_recent', 'bartik_shortcut_shortcuts', 'bartik_system_management', 'bartik_system_user-menu', 'bartik_system_main-menu', 'bartik_user_new', 'bartik_user_online', 'seven_comment_recent', 'seven_node_syndicate', 'seven_shortcut_shortcuts', 'seven_system_powered-by', 'seven_system_navigation', 'seven_system_management', 'seven_system_user-menu', 'seven_system_main-menu', 'seven_user_online', 'bartik_blog_recent', 'bartik_book_navigation', 'bartik_locale_language', 'bartik_forum_active', 'bartik_forum_new', 'seven_blog_recent', 'seven_book_navigation', 'seven_locale_language', 'seven_forum_active', 'seven_forum_new', 'bartik_menu_menu-test-menu', 'bartik_statistics_popular', 'seven_menu_menu-test-menu', 'seven_statistics_popular', 'seven_block_1'];
$this->assertTrue(empty(Block::loadMultiple($non_existent_blocks)));
}
示例5: testBlockMigration
/**
* Test the block settings migration.
*/
public function testBlockMigration()
{
$blocks = Block::loadMultiple();
$this->assertEqual(count($blocks), 8);
// User blocks
$test_block_user = $blocks['user'];
$this->assertNotNull($test_block_user);
$this->assertEqual('sidebar_first', $test_block_user->get('region'));
$this->assertEqual('bartik', $test_block_user->get('theme'));
$visibility = $test_block_user->getVisibility();
$this->assertEqual(TRUE, $visibility['request_path']['negate']);
$this->assertEqual('', $visibility['request_path']['pages']);
$this->assertEqual(0, $test_block_user->weight);
$test_block_user_1 = $blocks['user_1'];
$this->assertNotNull($test_block_user_1);
$this->assertEqual('sidebar_first', $test_block_user_1->get('region'));
$this->assertEqual('bartik', $test_block_user_1->get('theme'));
$visibility = $test_block_user_1->getVisibility();
$this->assertEqual(TRUE, $visibility['request_path']['negate']);
$this->assertEqual('', $visibility['request_path']['pages']);
$this->assertEqual(0, $test_block_user_1->weight);
// Check system block
$test_block_system = $blocks['system'];
$this->assertNotNull($test_block_system);
$this->assertEqual('footer', $test_block_system->get('region'));
$this->assertEqual('bartik', $test_block_system->get('theme'));
$visibility = $test_block_system->getVisibility();
$this->assertEqual(TRUE, $visibility['request_path']['negate']);
$this->assertEqual('', $visibility['request_path']['pages']);
$this->assertEqual(-5, $test_block_system->weight);
// Check menu blocks
$test_block_menu = $blocks['menu'];
$this->assertNotNull($test_block_menu);
$this->assertEqual('header', $test_block_menu->get('region'));
$this->assertEqual('bartik', $test_block_menu->get('theme'));
$visibility = $test_block_menu->getVisibility();
$this->assertEqual(TRUE, $visibility['request_path']['negate']);
$this->assertEqual('', $visibility['request_path']['pages']);
$this->assertEqual(-5, $test_block_menu->weight);
// Check custom blocks
$test_block_block = $blocks['block'];
$this->assertNotNull($test_block_block);
$this->assertEqual('content', $test_block_block->get('region'));
$this->assertEqual('bartik', $test_block_block->get('theme'));
$visibility = $test_block_block->getVisibility();
$this->assertEqual(FALSE, $visibility['request_path']['negate']);
$this->assertEqual('<front>', $visibility['request_path']['pages']);
$this->assertEqual(0, $test_block_block->weight);
$test_block_block_1 = $blocks['block_1'];
$this->assertNotNull($test_block_block_1);
$this->assertEqual('right', $test_block_block_1->get('region'));
$this->assertEqual('bluemarine', $test_block_block_1->get('theme'));
$visibility = $test_block_block_1->getVisibility();
$this->assertEqual(FALSE, $visibility['request_path']['negate']);
$this->assertEqual('node', $visibility['request_path']['pages']);
$this->assertEqual(-4, $test_block_block_1->weight);
$test_block_block_2 = $blocks['block_2'];
$this->assertNotNull($test_block_block_2);
$this->assertEqual('right', $test_block_block_2->get('region'));
$this->assertEqual('test_theme', $test_block_block_2->get('theme'));
$visibility = $test_block_block_2->getVisibility();
$this->assertEqual(TRUE, $visibility['request_path']['negate']);
$this->assertEqual('', $visibility['request_path']['pages']);
$this->assertEqual(-7, $test_block_block_2->weight);
$test_block_block_3 = $blocks['block_3'];
$this->assertNotNull($test_block_block_3);
$this->assertEqual('left', $test_block_block_3->get('region'));
$this->assertEqual('test_theme', $test_block_block_3->get('theme'));
$visibility = $test_block_block_3->getVisibility();
$this->assertEqual(TRUE, $visibility['request_path']['negate']);
$this->assertEqual('', $visibility['request_path']['pages']);
$this->assertEqual(-2, $test_block_block_3->weight);
}
示例6: postDelete
/**
* {@inheritdoc}
*/
public static function postDelete(EntityStorageInterface $storage, array $entities)
{
parent::postDelete($storage, $entities);
/** @var \Drupal\simplenews\Subscription\SubscriptionManagerInterface $subscription_manager */
$subscription_manager = \Drupal::service('simplenews.subscription_manager');
foreach ($entities as $newsletter) {
$subscription_manager->deleteSubscriptions(array('subscriptions_target_id' => $newsletter->id()));
drupal_set_message(t('All subscriptions to newsletter %newsletter have been deleted.', array('%newsletter' => $newsletter->label())));
}
if (\Drupal::moduleHandler()->moduleExists('block')) {
// Make sure there are no active blocks for these newsletters.
$ids = \Drupal::entityQuery('block')->condition('plugin', 'simplenews_subscription_block')->condition('settings.newsletters.*', array_keys($entities), 'IN')->execute();
if ($ids) {
$blocks = Block::loadMultiple($ids);
foreach ($blocks as $block) {
$settings = $block->get('settings');
foreach ($entities as $newsletter) {
if (in_array($newsletter->id(), $settings['newsletters'])) {
unset($settings['newsletters'][array_search($newsletter->id(), $settings['newsletters'])]);
}
}
// If there are no enabled newsletters left, delete the block.
if (empty($settings['newsletters'])) {
$block->delete();
} else {
// otherwise, update the settings and save.
$block->set('settings', $settings);
$block->save();
}
}
}
}
}