class Block in Open Social 8
Same name and namespace in other branches
- 8.9 themes/socialbase/src/Plugin/Preprocess/Block.php \Drupal\socialbase\Plugin\Preprocess\Block
- 8.2 themes/socialbase/src/Plugin/Preprocess/Block.php \Drupal\socialbase\Plugin\Preprocess\Block
- 8.3 themes/socialbase/src/Plugin/Preprocess/Block.php \Drupal\socialbase\Plugin\Preprocess\Block
- 8.4 themes/socialbase/src/Plugin/Preprocess/Block.php \Drupal\socialbase\Plugin\Preprocess\Block
- 8.5 themes/socialbase/src/Plugin/Preprocess/Block.php \Drupal\socialbase\Plugin\Preprocess\Block
- 8.6 themes/socialbase/src/Plugin/Preprocess/Block.php \Drupal\socialbase\Plugin\Preprocess\Block
- 8.7 themes/socialbase/src/Plugin/Preprocess/Block.php \Drupal\socialbase\Plugin\Preprocess\Block
- 8.8 themes/socialbase/src/Plugin/Preprocess/Block.php \Drupal\socialbase\Plugin\Preprocess\Block
Pre-processes variables for the "block" theme hook.
Plugin annotation
@BootstrapPreprocess("block");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\bootstrap\Plugin\PluginBase
- class \Drupal\bootstrap\Plugin\Preprocess\PreprocessBase implements PreprocessInterface
- class \Drupal\socialbase\Plugin\Preprocess\Block
- class \Drupal\bootstrap\Plugin\Preprocess\PreprocessBase implements PreprocessInterface
- class \Drupal\bootstrap\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Block
8 string references to 'Block'
- paragraphs.paragraphs_type.block.yml in modules/
social_features/ social_landing_page/ config/ install/ paragraphs.paragraphs_type.block.yml - modules/social_features/social_landing_page/config/install/paragraphs.paragraphs_type.block.yml
- SocialPostPostForm::buildOptionsForm in modules/
social_features/ social_post/ src/ Plugin/ views/ area/ SocialPostPostForm.php - Provide a form to edit options for this plugin.
- views.view.activity_stream_notifications.yml in modules/
social_features/ social_activity/ config/ install/ views.view.activity_stream_notifications.yml - modules/social_features/social_activity/config/install/views.view.activity_stream_notifications.yml
- views.view.activity_stream_profile.yml in modules/
social_features/ social_activity/ config/ install/ views.view.activity_stream_profile.yml - modules/social_features/social_activity/config/install/views.view.activity_stream_profile.yml
- views.view.event_enrollments.yml in modules/
social_features/ social_event/ config/ install/ views.view.event_enrollments.yml - modules/social_features/social_event/config/install/views.view.event_enrollments.yml
File
- themes/
socialbase/ src/ Plugin/ Preprocess/ Block.php, line 18
Namespace
Drupal\socialbase\Plugin\PreprocessView source
class Block extends PreprocessBase {
/**
* {@inheritdoc}
*/
public function preprocess(array &$variables, $hook, array $info) {
parent::preprocess($variables, $hook, $info);
// Early return because block missing ID, for example because
// Rendered in panels display
// https://www.drupal.org/node/2873726
if (empty($variables['elements']['#id'])) {
return;
}
// Find out what the active theme is first.
$theme = \Drupal::theme()
->getActiveTheme();
$route_name = \Drupal::routeMatch()
->getRouteName();
// Get the region of a block.
$region = '';
$block_entity = BlockEntity::load($variables['elements']['#id']);
if ($block_entity) {
$region = $block_entity
->getRegion();
}
$prefix = '';
// If socialbase is one of the basetheme, we need a prefix for block ids.
if (array_key_exists('socialbase', $theme
->getBaseThemes())) {
$prefix = $theme
->getName();
}
$variables['card'] = FALSE;
$regions_card = [
'complementary',
'complementary_top',
'complementary_bottom',
'content_top',
'content_bottom',
'',
];
if (in_array($region, $regions_card)) {
$variables['card'] = TRUE;
if (array_key_exists('socialbase', $theme
->getBaseThemes())) {
$prefix = $theme
->getName() . '_';
}
$block_buttons = [
$prefix . 'event_add_block',
$prefix . 'topic_add_block',
$prefix . 'group_add_block',
$prefix . 'group_add_event_block',
$prefix . 'group_add_topic_block',
];
if (in_array($variables['elements']['#id'], $block_buttons)) {
$variables['card'] = FALSE;
}
}
if (isset($variables['elements']['kpi_analytics'])) {
$variables['card'] = TRUE;
}
// Wrap the group/membership table in a card element.
if (isset($variables['elements']['#plugin_id']) && $variables['elements']['#plugin_id'] == 'system_main_block' && $route_name == 'entity.group_content.collection') {
$variables['card'] = TRUE;
}
// Show group managers block in a card.
if ($variables['elements']['#derivative_plugin_id'] == 'group_managers-block_list_managers') {
$variables['card'] = TRUE;
}
// For all platform_intro blocks we want them to appear as cards.
if (isset($variables['elements']['content']['#block_content'])) {
if ($variables['elements']['content']['#block_content']
->bundle() == 'platform_intro') {
$variables['card'] = TRUE;
}
}
$variables['content']['#attributes']['block'] = $variables['attributes']['id'];
// Fix label for Views exposed filter blocks.
if (!empty($variables['configuration']['views_label']) && empty($variables['configuration']['label'])) {
$variables['label'] = $variables['configuration']['views_label'];
}
// Check if the block is a views exposed form filter, add condition to add
// classes in twig file.
if (isset($variables['content']['#form_id']) && $variables['content']['#form_id'] == 'views_exposed_form') {
$variables['complementary'] = TRUE;
}
// Add search_block to main menu.
if ($variables['elements']['#id'] == 'mainnavigation' || $variables['elements']['#id'] == $prefix . '_mainnavigation') {
$block_id = \Drupal::moduleHandler()
->moduleExists('social_geolocation') ? 'geolocation_search_content_block_header' : 'search_content_block_header';
$block = BlockEntity::load($block_id);
if (!empty($block)) {
$block_output = \Drupal::entityManager()
->getViewBuilder('block')
->view($block);
$variables['content']['links']['search_block'] = $block_output;
}
}
// Preprocess search block header.
if (isset($variables['content']['search_form'])) {
$variables['content']['search_form']['#attributes']['role'] = 'search';
$variables['content']['search_form']['actions']['submit']['#is_button'] = FALSE;
$variables['content']['search_form']['actions']['#addsearchicon'] = TRUE;
if ($region == 'hero') {
$variables['content']['search_form']['#attributes']['class'][] = 'hero-form';
$variables['content']['search_form']['#region'] = 'hero';
$variables['content']['search_form']['actions']['submit']['#addsearchicon'] = TRUE;
}
elseif ($region == 'content_top') {
$variables['content']['search_form']['#region'] = 'content-top';
$variables['content']['search_form']['search_input_content']['#attributes']['placeholder'] = t('What are you looking for ?');
$variables['content']['search_form']['search_input_content']['#attributes']['autocomplete'] = 'off';
}
else {
$variables['content']['search_form']['#attributes']['class'][] = 'navbar-form';
}
}
// Add Group ID for "See all groups link".
if ($variables['attributes']['id'] === 'block-views-block-group-members-block-newest-members') {
$group = \Drupal::routeMatch()
->getParameter('group');
$variables['group_id'] = $group
->id();
}
// Add User ID for "See all link".
if ($variables['attributes']['id'] === 'block-views-block-events-block-events-on-profile' || $variables['attributes']['id'] === 'block-views-block-topics-block-user-topics' || $variables['attributes']['id'] === 'block-views-block-groups-block-user-groups') {
$profile_user_id = \Drupal::routeMatch()
->getParameter('user');
if (!is_null($profile_user_id) && is_object($profile_user_id)) {
$profile_user_id = $profile_user_id
->id();
}
$variables['profile_user_id'] = $profile_user_id;
}
// AN Homepage block.
if (isset($variables['elements']['content']['#block_content'])) {
if ($variables['elements']['content']['#block_content']
->bundle() == 'hero_call_to_action_block') {
if (isset($variables['elements']['content']['field_hero_image'])) {
$imageitem = $variables['elements']['content']['field_hero_image'][0]['#item']
->getEntity();
$imagestyle = $variables['elements']['content']['field_hero_image'][0]['#image_style'];
$entity = BlockContent::load($imageitem
->id());
$file_id = $entity
->get('field_hero_image')->target_id;
// First filter out image_style,
// So responsive image module doesn't break.
if (isset($imagestyle)) {
// If it's an existing file.
if ($file = File::load($file_id)) {
// Style and set it in the content.
$styled_image_url = ImageStyle::load($imagestyle)
->buildUrl($file
->getFileUri());
$variables['image_url'] = $styled_image_url;
// Add extra class.
$variables['has_image'] = TRUE;
// Remove the original.
unset($variables['content']['field_hero_image']);
}
}
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Block:: |
public | function |
Preprocess theme hook variables. Overrides PreprocessBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
protected | property | The currently set theme object. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
PreprocessBase:: |
protected | property | The theme hook invoked. | |
PreprocessBase:: |
protected | property | The theme hook info array from the theme registry. | |
PreprocessBase:: |
protected | property | The Variables object. | |
PreprocessBase:: |
protected | function | Ensures all attributes have been converted to an Attribute object. | |
PreprocessBase:: |
protected | function | Converts any set description variable into a traversable array. | |
PreprocessBase:: |
protected | function | Preprocess the variables array if an element is present. | 8 |
PreprocessBase:: |
protected | function | Preprocess the variables array. | 15 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |