You are here

class SocialContentBlockLandingPageContentBuilder in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_content_block/modules/social_content_block_landing_page/src/Service/SocialContentBlockLandingPageContentBuilder.php \Drupal\social_content_block_landing_page\Service\SocialContentBlockLandingPageContentBuilder
  2. 10.3.x modules/social_features/social_content_block/modules/social_content_block_landing_page/src/Service/SocialContentBlockLandingPageContentBuilder.php \Drupal\social_content_block_landing_page\Service\SocialContentBlockLandingPageContentBuilder
  3. 10.1.x modules/social_features/social_content_block/modules/social_content_block_landing_page/src/Service/SocialContentBlockLandingPageContentBuilder.php \Drupal\social_content_block_landing_page\Service\SocialContentBlockLandingPageContentBuilder
  4. 10.2.x modules/social_features/social_content_block/modules/social_content_block_landing_page/src/Service/SocialContentBlockLandingPageContentBuilder.php \Drupal\social_content_block_landing_page\Service\SocialContentBlockLandingPageContentBuilder

Class SocialContentBlockLandingPageContentBuilder.

@package Drupal\social_content_block_landing_page\Service

Hierarchy

Expanded class hierarchy of SocialContentBlockLandingPageContentBuilder

1 string reference to 'SocialContentBlockLandingPageContentBuilder'
social_content_block_landing_page.services.yml in modules/social_features/social_content_block/modules/social_content_block_landing_page/social_content_block_landing_page.services.yml
modules/social_features/social_content_block/modules/social_content_block_landing_page/social_content_block_landing_page.services.yml
1 service uses SocialContentBlockLandingPageContentBuilder
social_content_block_landing_page.content_builder in modules/social_features/social_content_block/modules/social_content_block_landing_page/social_content_block_landing_page.services.yml
Drupal\social_content_block_landing_page\Service\SocialContentBlockLandingPageContentBuilder

File

modules/social_features/social_content_block/modules/social_content_block_landing_page/src/Service/SocialContentBlockLandingPageContentBuilder.php, line 15

Namespace

Drupal\social_content_block_landing_page\Service
View source
class SocialContentBlockLandingPageContentBuilder extends ContentBuilder implements TrustedCallbackInterface {

  /**
   * {@inheritdoc}
   */
  public function build($entity_id, $entity_type_id, $entity_bundle) : array {
    $build = parent::build($entity_id, $entity_type_id, $entity_bundle);
    if (!$build) {
      return $build;
    }
    $weight = 1;
    foreach (Element::children($build['content']) as $key) {
      $build['content'][$key]['#weight'] = $weight++;
    }
    $build['content']['title'] = [
      '#type' => 'html_tag',
      '#tag' => 'h2',
      '#attributes' => [
        'class' => [
          'title',
        ],
      ],
      '#value' => $this->entityTypeManager
        ->getStorage($entity_type_id)
        ->load($entity_id)->field_subtitle->value,
      '#weight' => 0,
    ];
    if (!isset($build['content']['entities']['#markup']) && !isset($build['content']['entities']['#lazy_builder'])) {
      $build['content']['entities']['#prefix'] = str_replace('content-list__items', 'field--name-field-featured-items', $build['content']['entities']['#prefix']);
    }
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function getEntities($block_id) {
    $elements = parent::getEntities($block_id);
    foreach (Element::children($elements) as $delta) {
      $elements[$delta]['#custom_content_list_section'] = TRUE;
    }
    return $elements;
  }

  /**
   * {@inheritdoc}
   */
  protected function getLink(BlockContentInterface $block_content) : array {
    if ($link = parent::getLink($block_content)) {
      $link['#url']
        ->setOption('attributes', []);
      $link = [
        '#type' => 'container',
        '#attributes' => [
          'class' => [
            'card__link',
          ],
        ],
        'link' => $link,
      ];
    }
    return $link;
  }

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'build',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentBuilder::$connection protected property The current active database's master connection.
ContentBuilder::$contentBlockManager protected property The content block manager.
ContentBuilder::$entityTypeManager protected property The entity type manager.
ContentBuilder::$moduleHandler protected property The module handler service.
ContentBuilder::processBlockForm public static function Process callback to insert a Custom Block form.
ContentBuilder::sortBy protected function Sorting and range logic by specific case.
ContentBuilder::updateFormSortingOptions public function Update the sorting field after a plugin choice change.
ContentBuilder::__construct public function ContentBuilder constructor.
SocialContentBlockLandingPageContentBuilder::build public function Lazy builder callback for displaying a content blocks. Overrides ContentBuilder::build
SocialContentBlockLandingPageContentBuilder::getEntities public function Function to get all the entities based on the filters. Overrides ContentBuilder::getEntities
SocialContentBlockLandingPageContentBuilder::getLink protected function Function to generate the read more link. Overrides ContentBuilder::getLink
SocialContentBlockLandingPageContentBuilder::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides ContentBuilder::trustedCallbacks
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.