Same name in other branches
- 7.x-3.x plugins/QuickBlockContent.inc \QuickBlockContent
Class for tab content of type "block" - this is for rendering a block as tab content. @QuicktabFormat{ id = "quickblockcontent
Hierarchy
- class \Drupal\quicktabs\QuickContent implements \Drupal\quicktabs\QuickContentRenderableInterface
- class \Drupal\quicktabs\Plugin\QuickContent\QuickBlockContent extends \Drupal\quicktabs\QuickContent implements \Drupal\quicktabs\QuicktabContentInterface
Expanded class hierarchy of QuickBlockContent
1 string reference to 'QuickBlockContent'
- quicktabs_quicktabs_contents in ./
quicktabs.module - Implements hook_quicktabs_contents().
File
-
src/
Plugin/ QuickContent/ QuickBlockContent.php, line 19
Namespace
Drupal\quicktabs\Plugin\QuickContentView source
class QuickBlockContent extends QuickContent implements QuicktabContentInterface {
/**
* {@inheritdoc}
*/
public static function getType() {
return 'block';
}
/**
* {@inheritdoc}
*/
public function optionsForm($delta, $qt, $form_state) {
$tab = $this->settings;
$form = array();
$form['block']['bid'] = array(
'#type' => 'select',
'#options' => quicktabs_get_blocks(),
'#default_value' => isset($tab['bid']) ? $tab['bid'] : '',
'#title' => t('Select a block'),
);
$form['block']['hide_title'] = array(
'#type' => 'checkbox',
'#title' => t('Hide the title of this block'),
'#default_value' => isset($tab['hide_title']) ? $tab['hide_title'] : 1,
);
return $form;
}
/**
* {@inheritdoc}
*/
public function render($hide_empty = FALSE, $args = array()) {
if ($this->rendered_content) {
return $this->rendered_content;
}
$output = array();
$item = $this->settings;
if (!empty($args)) {
// The args have been passed in from an ajax request.
$qt_name = array_shift($args);
list($item['bid'], $item['hide_title']) = $args;
// Ensure the block is assigned to the requested quicktabs block. This test prevents
// AJAX access to blocks that have not been added to an AJAX-enabled quicktabs block.
$break = TRUE;
$quicktabs = quicktabs_load($qt_name);
// Ensure AJAX is enabled for the quicktabs block.
if (!empty($quicktabs) && $quicktabs->ajax == 1) {
// Ensure the requested tab has been added to the quicktabs block.
foreach ($quicktabs->tabs as $quicktab) {
if (isset($quicktab['bid']) && $quicktab['bid'] == $item['bid']) {
$break = FALSE;
break;
}
}
}
if ($break == TRUE) {
if (!$hide_empty) {
$output['#markup'] = theme('quicktabs_tab_access_denied', $item);
}
return $output;
}
}
if (isset($item['bid'])) {
if (\Drupal::moduleHandler()->moduleExists('block')) {
$pos = strpos($item['bid'], '_delta_');
$module = drupal_substr($item['bid'], 0, $pos);
$delta = drupal_substr($item['bid'], $pos + 7);
// Make sure the user can access the block.
if ($this->accessBlock($module, $delta)) {
$block = block_load($module, $delta);
$block->region = 'quicktabs_tabpage';
if ($block_arr = _block_render_blocks(array(
$block,
))) {
if ($item['hide_title']) {
$block_arr["{$block->module}_{$block->delta}"]->subject = FALSE;
}
if (!empty($block_arr["{$block->module}_{$block->delta}"]->content)) {
$build = _block_get_renderable_array($block_arr);
$output = $build;
}
}
}
elseif (!$hide_empty) {
$output['#markup'] = theme('quicktabs_tab_access_denied', $item);
}
}
elseif (!$hide_empty) {
$output['#markup'] = t('Block module is not enabled, cannot display content.');
}
}
$this->rendered_content = $output;
return $output;
}
/**
* {@inheritdoc}
*/
public function getAjaxKeys() {
return array(
'bid',
'hide_title',
);
}
/**
* {@inheritdoc}
*/
public function getUniqueKeys() {
return array(
'bid',
);
}
/**
* Checks if the current user can access a block.
*/
private function accessBlock($module, $delta) {
// Get current user's rids.
global $user;
$rids = array_keys($user->roles);
// Get authorized rids.
$authorized_rids = db_select('block_role', 'br')->fields('br', array(
'rid',
))
->condition('module', $module, '=')
->condition('delta', $delta, '=')
->execute()
->fetchCol('rid');
// Return whether the user can access the block:
// - Either all roles have access - no record in {block_role}
// - Or only specific roles have access - in which case rids should match.
return count($authorized_rids) == 0 || count(array_intersect($authorized_rids, $rids)) != 0;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
QuickBlockContent::accessBlock | private | function | Checks if the current user can access a block. | ||
QuickBlockContent::getAjaxKeys | public | function | Returns an array of keys to use for constructing the correct arguments for an ajax callback to retrieve content of this type. The order of the keys returned affects the order of the args passed in to the render method when called via ajax (see theā¦ |
Overrides QuickContentRenderableInterface::getAjaxKeys | |
QuickBlockContent::getType | public static | function | Returns the short type name of the content plugin, e.g. 'block', 'node', 'prerendered'. |
Overrides QuickContentRenderableInterface::getType | |
QuickBlockContent::getUniqueKeys | public | function | Returns an array of keys, sufficient to represent the content uniquely. | Overrides QuickContentRenderableInterface::getUniqueKeys | |
QuickBlockContent::optionsForm | public | function | Method for returning the form elements to display for this tab type on the admin form. |
Overrides QuickContent::optionsForm | |
QuickBlockContent::render | public | function | Renders the content. | Overrides QuickContentRenderableInterface::render | |
QuickContent::$rendered_content | protected | property | A render array of the contents. | ||
QuickContent::$settings | protected | property | An array containing the information that defines the tab content, specific to its type. |
||
QuickContent::$title | protected | property | Used as the title of the tab. | ||
QuickContent::factory | public static | function | Instantiate a content type object. | ||
QuickContent::getSettings | public | function | Accessor for the tab settings. | Overrides QuickContentRenderableInterface::getSettings | |
QuickContent::getTitle | public | function | Accessor for the tab title. | Overrides QuickContentRenderableInterface::getTitle | |
QuickContent::__construct | public | function | Constructor | 2 |