vais_promos-1.0.0-beta2/vais_promos.module
vais_promos.module
<?php
/**
* @file
* Vertex AI Search Promos module file.
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/**
* Implements hook_help().
*/
function vais_promos_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.vais_promos':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>';
$output .= t('The Vertex AI Search Promotions module provides for the
<a href=":promoAdmin">administration of promoted search results</a>
associated with search keywords. For a given keyword, a content node
can be specified as a promoted result. The promoted result will appear
at the top of the search results page when a search against the
given keyword is performed.',
[
':promoAdmin' => Url::fromRoute(
'entity.vais_promo.collection'
)->toString(),
]);
$output .= '</p>';
$output .= '<h3>' . t('Documentation') . '</h3>';
$output .= '<p>';
$output .= t('Refer to the <a href=":background">module background
documentation</a> for information about the need for this module.',
[
':background' => 'https://www.drupal.org/docs/extending-drupal/contributed-modules/contributed-module-documentation/vertex-ai-search-promoted-results/module-background',
]);
$output .= '</p>';
$output .= '<p>';
$output .= t('For information on configuring and using this module,
see "<a href=":creating">Creating a Promoted Search Result</a>".',
[
':creating' => 'https://www.drupal.org/docs/extending-drupal/contributed-modules/contributed-module-documentation/vertex-ai-search-promoted-results/creating-a-promoted-search-result',
]);
$output .= '</p>';
return $output;
}
}
/**
* Implements hook_theme().
*/
function vais_promos_theme($existing, $type, $theme, $path) {
return [
'vais_promos_promotion' => [
'variables' => [
'title' => NULL,
'description' => NULL,
'promo_type' => NULL,
'href' => NULL,
'term' => NULL,
],
'file' => 'vais_promos.theme.inc',
'template' => 'vais_promos_promotion',
],
];
}
/**
* Implements hook_entity_base_field_info_alter().
*/
function vais_promos_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
if ($entity_type->id() == 'vais_promo' && !empty($fields['promo_content'])) {
$vaisPromoSettings = \Drupal::configFactory()->get('vais_promos.entity_type_settings');
$vaisPromoBundles = $vaisPromoSettings->get('vais_promo_types');
$handlerSettings = $fields['promo_content']->getSetting('handler_settings');
if (empty($vaisPromoBundles)) {
unset($handlerSettings['target_bundles']);
}
else {
$handlerSettings['target_bundles'] = array_keys($vaisPromoBundles);
}
$fields['promo_content']->setSetting('handler_settings', $handlerSettings);
}
}
