<?php

/**
 * @file
 * Contains social_page.module..
 */

use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\node\NodeInterface;

/**
 * Implements hook_help().
 */
function social_page_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the social_page module.
    case 'help.page.social_page':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Use basic pages for your static content, such as an about page.') . '</p>';
      return $output;

    default:
  }
}

/**
 * Implements hook_node_links_alter().
 */
function social_page_node_links_alter(array &$links, NodeInterface $entity, array &$context) {
  // Remove the add new comment link.
  unset($links['comment__field_page_comments']['#links']['comment-add']);
}

/**
 * Implements hook_social_tagging_type_alter().
 */
function social_page_social_tagging_type_alter(array &$items): void {
  $items['node']['sets'][0]['bundles'][] = 'page';
}

/**
 * Implements hook_social_user_account_header_create_links().
 *
 * Adds the "Create Page" link to the content creation menu.
 */
function social_page_social_user_account_header_create_links($context) {
  $link = Link::createFromRoute((new TranslatableMarkup('New Page')), 'node.add', [
    'node_type' => 'page',
  ]);

  return [
    'add_page' => [
      '#type' => 'link',
      '#attributes' => [
        'title' => new TranslatableMarkup('Create New Page'),
      ],
      '#weight' => 300,
      '#access' => $link->getUrl()->access(),
    ] + $link->toRenderable(),
  ];
}
