class Block
Same name in this branch
- 9 core/modules/views/src/Plugin/views/display/Block.php \Drupal\views\Plugin\views\display\Block
- 9 core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block
- 9 core/lib/Drupal/Core/Block/Annotation/Block.php \Drupal\Core\Block\Annotation\Block
Same name and namespace in other branches
- 11.x core/modules/views/src/Plugin/views/display/Block.php \Drupal\views\Plugin\views\display\Block
- 11.x core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block
- 11.x core/modules/block/src/Plugin/migrate/source/Block.php \Drupal\block\Plugin\migrate\source\Block
- 11.x core/lib/Drupal/Core/Block/Attribute/Block.php \Drupal\Core\Block\Attribute\Block
- 11.x core/lib/Drupal/Core/Block/Annotation/Block.php \Drupal\Core\Block\Annotation\Block
- 10 core/modules/views/src/Plugin/views/display/Block.php \Drupal\views\Plugin\views\display\Block
- 10 core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block
- 10 core/modules/block/src/Plugin/migrate/source/Block.php \Drupal\block\Plugin\migrate\source\Block
- 10 core/lib/Drupal/Core/Block/Attribute/Block.php \Drupal\Core\Block\Attribute\Block
- 10 core/lib/Drupal/Core/Block/Annotation/Block.php \Drupal\Core\Block\Annotation\Block
- 8.9.x core/modules/views/src/Plugin/views/display/Block.php \Drupal\views\Plugin\views\display\Block
- 8.9.x core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block
- 8.9.x core/modules/block/src/Plugin/migrate/source/Block.php \Drupal\block\Plugin\migrate\source\Block
- 8.9.x core/lib/Drupal/Core/Block/Annotation/Block.php \Drupal\Core\Block\Annotation\Block
Drupal 6/7 block source from database.
For available configuration keys, refer to the parent classes.
Plugin annotation
@MigrateSource(
id = "block",
source_module = "block"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\migrate\Plugin\migrate\source\SourcePluginBase implements \Drupal\migrate\Plugin\MigrateSourceInterface, \Drupal\migrate\Event\RollbackAwareInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\migrate\Plugin\migrate\source\SqlBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\migrate\Plugin\RequirementsInterface extends \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
- class \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase implements \Drupal\Component\Plugin\DependentPluginInterface uses \Drupal\Core\Entity\DependencyTrait extends \Drupal\migrate\Plugin\migrate\source\SqlBase
- class \Drupal\block\Plugin\migrate\source\Block extends \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
- class \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase implements \Drupal\Component\Plugin\DependentPluginInterface uses \Drupal\Core\Entity\DependencyTrait extends \Drupal\migrate\Plugin\migrate\source\SqlBase
- class \Drupal\migrate\Plugin\migrate\source\SqlBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\migrate\Plugin\RequirementsInterface extends \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
- class \Drupal\migrate\Plugin\migrate\source\SourcePluginBase implements \Drupal\migrate\Plugin\MigrateSourceInterface, \Drupal\migrate\Event\RollbackAwareInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of Block
See also
\Drupal\migrate\Plugin\migrate\source\SqlBase
\Drupal\migrate\Plugin\migrate\source\SourcePluginBase
2 files declare their use of Block
- BlockTranslation.php in core/
modules/ block/ src/ Plugin/ migrate/ source/ d6/ BlockTranslation.php - BlockTranslation.php in core/
modules/ block/ src/ Plugin/ migrate/ source/ d7/ BlockTranslation.php
195 string references to 'Block'
- aggregator_help in core/
modules/ aggregator/ aggregator.module - Implements hook_help().
- AjaxFormCacheTest::testBlockForms in core/
tests/ Drupal/ FunctionalJavascriptTests/ Ajax/ AjaxFormCacheTest.php - Tests AJAX forms in blocks.
- AjaxFormCacheTest::testQueryString in core/
tests/ Drupal/ FunctionalJavascriptTests/ Ajax/ AjaxFormCacheTest.php - Tests AJAX forms on pages with a query string.
- AreaDisplayLinkTest::setUp in core/
modules/ views/ tests/ src/ Kernel/ Handler/ AreaDisplayLinkTest.php - block.info.yml in core/
modules/ block/ block.info.yml - core/modules/block/block.info.yml
File
-
core/
modules/ block/ src/ Plugin/ migrate/ source/ Block.php, line 23
Namespace
Drupal\block\Plugin\migrate\sourceView source
class Block extends DrupalSqlBase {
/**
* The default theme name.
*
* @var string
*/
protected $defaultTheme;
/**
* The admin theme name.
*
* @var string
*/
protected $adminTheme;
/**
* Table containing block configuration.
*
* @var string
*/
protected $blockTable;
/**
* Table mapping blocks to user roles.
*
* @var string
*/
protected $blockRoleTable;
/**
* Table listing user roles.
*
* @var string
*/
protected $userRoleTable;
/**
* {@inheritdoc}
*/
public function query() {
if ($this->getModuleSchemaVersion('system') >= 7000) {
$this->blockTable = 'block';
$this->blockRoleTable = 'block_role';
}
else {
$this->blockTable = 'blocks';
$this->blockRoleTable = 'blocks_roles';
}
// Drupal 6 & 7 both use the same name for the user roles table.
$this->userRoleTable = 'role';
return $this->select($this->blockTable, 'b')
->fields('b');
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$this->defaultTheme = $this->variableGet('theme_default', 'Garland');
$this->adminTheme = $this->variableGet('admin_theme', NULL);
return parent::initializeIterator();
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'bid' => $this->t('The block numeric identifier.'),
'module' => $this->t('The module providing the block.'),
'delta' => $this->t("The block's delta."),
'theme' => $this->t('Which theme the block is placed in.'),
'status' => $this->t('Whether or not the block is enabled.'),
'weight' => $this->t('Weight of the block for ordering within regions.'),
'region' => $this->t('Region the block is placed in.'),
'visibility' => $this->t('Visibility expression.'),
'pages' => $this->t('Pages list.'),
'title' => $this->t('Block title.'),
'cache' => $this->t('Cache rule.'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['module']['type'] = 'string';
$ids['delta']['type'] = 'string';
$ids['theme']['type'] = 'string';
return $ids;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$row->setSourceProperty('default_theme', $this->defaultTheme);
$row->setSourceProperty('admin_theme', $this->adminTheme);
$module = $row->getSourceProperty('module');
$delta = $row->getSourceProperty('delta');
$query = $this->select($this->blockRoleTable, 'br')
->fields('br', [
'rid',
])
->condition('module', $module)
->condition('delta', $delta);
$query->join($this->userRoleTable, 'ur', '[br].[rid] = [ur].[rid]');
$roles = $query->execute()
->fetchCol();
$row->setSourceProperty('roles', $roles);
$settings = [];
switch ($module) {
case 'aggregator':
[$type, $id] = explode('-', $delta);
if ($type == 'feed') {
$item_count = $this->select('aggregator_feed', 'af')
->fields('af', [
'block',
])
->condition('fid', $id)
->execute()
->fetchField();
}
else {
$item_count = $this->select('aggregator_category', 'ac')
->fields('ac', [
'block',
])
->condition('cid', $id)
->execute()
->fetchField();
}
$settings['aggregator']['item_count'] = $item_count;
break;
case 'book':
$settings['book']['block_mode'] = $this->variableGet('book_block_mode', 'all pages');
break;
case 'forum':
$settings['forum']['block_num'] = $this->variableGet('forum_block_num_' . $delta, 5);
break;
case 'statistics':
foreach ([
'statistics_block_top_day_num',
'statistics_block_top_all_num',
'statistics_block_top_last_num',
] as $name) {
$settings['statistics'][$name] = $this->variableGet($name, 0);
}
break;
case 'user':
switch ($delta) {
case 2:
case 'new':
$settings['user']['block_whois_new_count'] = $this->variableGet('user_block_whois_new_count', 5);
break;
case 3:
case 'online':
$settings['user']['block_seconds_online'] = $this->variableGet('user_block_seconds_online', 900);
$settings['user']['max_list_count'] = $this->variableGet('user_block_max_list_count', 10);
break;
}
break;
}
$row->setSourceProperty('settings', $settings);
return parent::prepareRow($row);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.