function share_everywhere_commerce_product_view in Share Everywhere 8
Same name and namespace in other branches
- 2.x share_everywhere.module \share_everywhere_commerce_product_view()
Implements hook_ENTITY_TYPE_view().
File
- ./
share_everywhere.module, line 186 - A module that adds social buttons to your website.
Code
function share_everywhere_commerce_product_view(array &$build, EntityInterface $product, EntityViewDisplayInterface $display, $view_mode) {
$config = \Drupal::config('share_everywhere.settings');
$share_service = \Drupal::service('share_everywhere.service');
$module_handler = \Drupal::service('module_handler');
if (!$module_handler
->moduleExists('commerce_product') || $share_service
->isRestricted($view_mode)) {
return;
}
$url = $product
->toUrl()
->setAbsolute()
->toString();
$id = $product
->getEntityTypeId() . $product
->id();
$enabled_types = $config
->get('product_types');
$enabled_view_modes = $config
->get('product_view_modes.' . $product
->bundle());
$per_entity = $config
->get('per_entity');
$enabled_products = $config
->get('enabled_entities.' . $product
->getEntityTypeId()) ?? [];
if ($config
->get('location') == 'content') {
if (isset($enabled_types[$product
->bundle()]) && $enabled_types[$product
->bundle()] === $product
->bundle() && $display
->getComponent('share_everywhere')) {
if (isset($enabled_view_modes[$view_mode]) && $enabled_view_modes[$view_mode]) {
if (!$per_entity || in_array($product
->id(), $enabled_products)) {
$build['share_everywhere'] = $share_service
->build($url, $id);
}
}
}
}
}