sector_long_form-1.0.x-dev/sector_long_form.module

sector_long_form.module
<?php
use Drupal\Core\Template\Attribute;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\sector_long_form\SectorLongFormInterface;

/**
 * Implements hook_theme().
 */
function sector_long_form_theme($existing, $type, $theme, $path) {
  return [
        'long_form_actions' => [
            'variables' => [
                'display' => NULL,
                'attributes' => NULL,
                'utility_classes' => [],
                'button_classes' => [],
            ],
            'render element' => 'element',
        ],
        'long_form_pager' => [
            'variables' => [
                'attributes' => NULL,
                'utility_classes' => []
            ],
            'render element' => 'element',
        ],
        'long_form_toc' => [
            'variables' => [
                'attributes' => NULL,
                'title' => NULL,
                'utility_classes' => []
            ],
            'render element' => 'element',
        ],
    ];
}

/**
 * Implements hook_entity_extra_field_info().
 */
function sector_long_form_entity_extra_field_info() {
    return [
        'node' => [
            'sector_long_form' => [
                'display' => [
                    'sector_long_form_pager' => [
                        'label' => t('Sector Long-form › Pager'),
                        'description' => t('Sector Long-form pager block pseudo field.'),
                        'weight' => 0,
                        'visible' => TRUE,
                        'type' => 'string',
                    ]
                ]
            ]
        ]
    ];
}

/**
 * Implements hook_node_view().
 */
function sector_long_form_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
    // Check if the entity is of type 'article' and the view mode matches.
    if ($entity->bundle() === 'sector_long_form' && $display->getComponent('sector_long_form_pager')) {
      // Add content to the custom field.
      $build['sector_long_form_pager'] = [
        '#type' => 'markup',
        '#theme' => 'long_form_pager',
        '#attributes' => new Attribute,
        '#utility_classes' => [
            SectorLongFormInterface::PAGER_CLASS,
            'multipage-pagination'    // remove
        ],
        '#attached' => [
            'library' => 'sector_long_form/app',
            'drupalSettings' => [
                'sector_long_form' => [
                    'chunker_class' => SectorLongFormInterface::CHUNKER_CLASS,
                    'pager_class' => SectorLongFormInterface::PAGER_CLASS,
                ],
            ],
        ],
        '#weight' => $display->getComponent('sector_long_form_pager')['weight'],
      ];
    }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc