diff --git a/embargo.module b/embargo.module index 473a00b..c7c0da4 100644 --- a/embargo.module +++ b/embargo.module @@ -9,6 +9,7 @@ use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Session\AccountInterface; use Drupal\embargo\EmbargoStorage; +use Drupal\node\NodeInterface; /** * Implements hook_entity_type_alter(). @@ -109,7 +110,7 @@ function embargo_embargo_update(EntityInterface $entity) { $node_reference = $entity->get('embargoed_node')->entity; // Check if the referenced entity is a node. - if ($node_reference instanceof \Drupal\node\NodeInterface) { + if ($node_reference instanceof NodeInterface) { // Load the node using the entity type manager. $entityTypeManager = \Drupal::entityTypeManager(); @@ -120,7 +121,8 @@ function embargo_embargo_update(EntityInterface $entity) { \Drupal::getContainer()->get('search_api.entity_datasource.tracking_manager') ->entityUpdate($node); - // Attempt to track all items as changed that indexed updated data indirectly. + // Attempt to track all items as changed that indexed + // updated data indirectly. \Drupal::getContainer()->get('search_api.tracking_helper') ->trackReferencedEntityUpdate($node); } diff --git a/src/Plugin/search_api/processor/EmbargoIpRestriction.php b/src/Plugin/search_api/processor/EmbargoIpRestriction.php index db04355..34a171e 100644 --- a/src/Plugin/search_api/processor/EmbargoIpRestriction.php +++ b/src/Plugin/search_api/processor/EmbargoIpRestriction.php @@ -26,7 +26,7 @@ * } * ) */ -class EmbargoIpRestriction extends ProcessorPluginBase implements ContainerFactoryPluginInterface{ +class EmbargoIpRestriction extends ProcessorPluginBase implements ContainerFactoryPluginInterface { /** * The request stack. @@ -66,7 +66,7 @@ class EmbargoIpRestriction extends ProcessorPluginBase implements ContainerFacto * @param mixed $plugin_definition * The plugin implementation definition. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. + * The request stack. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The Entity Type Manager. * @param \Drupal\Core\Session\AccountProxyInterface $currentUser @@ -74,7 +74,7 @@ class EmbargoIpRestriction extends ProcessorPluginBase implements ContainerFacto * * @throws \Drupal\facets\Exception\InvalidProcessorException */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, AccountProxyInterface $currentUser) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, AccountProxyInterface $currentUser) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->requestStack = $request_stack; $this->entityTypeManager = $entity_type_manager; @@ -181,7 +181,8 @@ public function preprocessSearchQuery(QueryInterface $query) { // Convert User IP into CIDR format query matching. $currentUserIpCidr = $this->ipToCidr($currentUserIp); - // Add the condition to check if the user's IP is in the list using CIDR notation + // Add the condition to check if the user's IP + // is in the list using CIDR notation $conditions->addCondition('embargo_ip', $currentUserIpCidr); $conditions->addCondition('embargo_ip', NULL); } @@ -205,22 +206,22 @@ public function preprocessSearchQuery(QueryInterface $query) { * @return string * The CIDR notation representation of the IP address. */ - function ipToCidr($ip, $subnetMask = 24) { + public function ipToCidr($ip, $subnetMask = 24) { // Check if the IP is IPv6. if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { - // For simplicity, let's assume a default subnet mask of 128 for IPv6 + // For simplicity, let's assume a default subnet mask of 128 for IPv6. return $ip . '/128'; } $ipParts = explode('.', $ip); - // Ensure subnet mask is within valid range (0-32) + // Ensure subnet mask is within valid range (0-32). $subnetMask = max(0, min(32, $subnetMask)); - // Calculate the network portion of the IP based on the subnet mask + // Calculate the network portion of the IP based on the subnet mask. $network = implode('.', array_slice($ipParts, 0, floor($subnetMask / 8))); - // Build the CIDR notation + // Build the CIDR notation. $cidr = $network . '.0/' . $subnetMask; return $cidr;