Skip to content

LOOP-844: Changes after external code review – hook doc block #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function os2loop_documents_help($route_name, RouteMatchInterface $route_match) {

/**
* Implements hook_form_BASE_FORM_ID_alter().
*
* @see \Drupal\os2loop_documents\Helper\FormHelper::alterForm()
*/
function os2loop_documents_form_node_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
// @todo We should use hook_event_dispatcher for this
Expand All @@ -36,13 +38,17 @@ function os2loop_documents_form_node_form_alter(array &$form, FormStateInterface

/**
* Implements hook_ENTITY_TYPE_update().
*
* @see \Drupal\os2loop_documents\Helper\NodeHelper::updateNode()
*/
function os2loop_documents_node_update(EntityInterface $entity) {
\Drupal::service('os2loop_documents.node_helper')->updateNode($entity);
}

/**
* Implements hook_preprocess_HOOK().
*
* @see \Drupal\os2loop_documents\Helper\NodeHelper::preprocessNode()
*/
function os2loop_documents_preprocess_node(array &$variables) {
\Drupal::service('os2loop_documents.node_helper')->preprocessNode($variables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public function __construct(CollectionHelper $collectionHelper, RendererInterfac

/**
* Implements hook_form_BASE_FORM_ID_alter().
*
* Hides legacy body field on non-legacy documents (cf.
* self::isLegacyDocument).
*
* Insert UI for adding documents to a collection.
*/
public function alterForm(array &$form, FormStateInterface $formState, string $formId) {
switch ($formId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public function updateNode(NodeInterface $node) {

/**
* Implements hook_preprocess_HOOK().
*
* Adds collection table of contents to collection and document views.
*
* Adds list of collections to document view (when document is in more than
* one colletion).
*/
public function preprocessNode(array &$variables) {
/** @var \Drupal\node\NodeInterface $node */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function os2loop_search_db_help($route_name, RouteMatchInterface $route_match) {

/**
* Implements hook_search_api_autocomplete_suggestions_alter().
*
* @see \Drupal\os2loop_search_db\Helper\SearchApiAutocompleteHelper::alterSuggestions()
*/
function os2loop_search_db_search_api_autocomplete_suggestions_alter(array &$suggestions, array $alter_params) {
$helper = \Drupal::service('os2loop_search_db.search_api_autocomplete_helper');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class SearchApiAutocompleteHelper {

/**
* Implements hook_search_api_autocomplete_suggestions_alter().
*
* Adds a suggestion, "See all results for …", linking to the full search
* result for the current query.
*/
public function alterSuggestions(array &$suggestions, array $alter_params) {
/** @var string $user_input */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@

/**
* Implements hook_preprocess_flag().
*
* @see \Drupal\os2loop_upvote\Helper\FlagHelper::preprocessFlag()
*/
function os2loop_upvote_preprocess_flag(array &$variables) {
Drupal::service('os2loop_upvote.flag_helper')->preprocessFlag($variables);
}

/**
* Implements hook_preprocess_field().
*
* @see \Drupal\os2loop_upvote\Helper\FlagHelper::preprocessField()
*/
function os2loop_upvote_preprocess_field(array &$variables, $hook) {
Drupal::service('os2loop_upvote.flag_helper')->preprocessField($variables);
}

/**
* Implements hook_preprocess_comment().
*
* @see \Drupal\os2loop_upvote\Helper\FlagHelper::preprocessComment()
*/
function os2loop_upvote_preprocess_comment(array &$variables) {
Drupal::service('os2loop_upvote.flag_helper')->preprocessComment($variables);
Expand Down
10 changes: 10 additions & 0 deletions web/profiles/custom/os2loop/os2loop.profile
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,44 @@ use Drupal\Core\Form\FormStateInterface;

/**
* Implements hook_entity_create_access().
*
* @see Helper::entityCreateAccess()
*/
function os2loop_entity_create_access(AccountInterface $account, array $context, $entity_bundle) {
return Drupal::service(Helper::class)->entityCreateAccess($account, $context, $entity_bundle);
}

/**
* Implements hook_node_access().
*
* @see Helper::nodeAccess()
*/
function os2loop_node_access(NodeInterface $node, $op, AccountInterface $account) {
return Drupal::service(Helper::class)->nodeAccess($node, $op, $account);
}

/**
* Implements hook_form_alter().
*
* @see Helper::formAlter()
*/
function os2loop_form_alter(&$form, FormStateInterface $form_state, $form_id) {
return Drupal::service(Helper::class)->formAlter($form, $form_state, $form_id);
}

/**
* Implements hook_preprocess_node().
*
* @see Helper::preprocessNode()
*/
function os2loop_preprocess_node(array &$variables) {
return Drupal::service(Helper::class)->preprocessNode($variables);
}

/**
* Implements hook_block_access().
*
* @see Helper::blockAccess()
*/
function os2loop_block_access(Block $block, $operation, AccountInterface $account) {
return Drupal::service(Helper::class)->blockAccess($block, $operation, $account);
Expand Down
10 changes: 10 additions & 0 deletions web/profiles/custom/os2loop/src/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function __construct(ConfigFactoryInterface $configFactory) {

/**
* Implements hook_entity_create_access().
*
* Checks if a node type is enabled (cf self::contentTypeAccess()).
*/
public function entityCreateAccess(AccountInterface $account, array $context, $entity_bundle): AccessResult {
if ('node' === $context['entity_type_id']) {
Expand All @@ -41,20 +43,26 @@ public function entityCreateAccess(AccountInterface $account, array $context, $e

/**
* Implements hook_node_access().
*
* Checks if a node type is enabled (cf self::contentTypeAccess()).
*/
public function nodeAccess(NodeInterface $node, $op, AccountInterface $account): AccessResult {
return $this->contentTypeAccess($node->bundle());
}

/**
* Implements hook_form_alter().
*
* Hides field for disabled taxonomies from a form.
*/
public function formAlter(&$form, FormStateInterface $form_state, $form_id) {
$this->hideTaxonomyVocabularies($form);
}

/**
* Implements hook_preprocess_node().
*
* Hides disabled taxonomies from a node.
*/
public function preprocessNode(array &$variables) {
if (isset($variables['content'])) {
Expand All @@ -67,6 +75,8 @@ public function preprocessNode(array &$variables) {

/**
* Implements hook_block_access().
*
* Hides disabled blocks.
*/
public function blockAccess(Block $block, $operation, AccountInterface $account) {
if ('view' === $operation) {
Expand Down