You are here

public function ConsentStorageBase::getCurrentPolicyNodeRevision in EU Cookie Compliance (GDPR Compliance) 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/ConsentStorageBase.php \Drupal\eu_cookie_compliance\Plugin\ConsentStorageBase::getCurrentPolicyNodeRevision()

Get the current revision of the privacy policy node.

Return value

bool|int Returns the latest revision ID of the curreny privacy policy node, or FALSE if no priacy policy exists.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to ConsentStorageBase::getCurrentPolicyNodeRevision()
BasicConsentStorage::registerConsent in src/Plugin/ConsentStorage/BasicConsentStorage.php
Register consent.

File

src/Plugin/ConsentStorageBase.php, line 95

Class

ConsentStorageBase
Provides a base class for a consent storage.

Namespace

Drupal\eu_cookie_compliance\Plugin

Code

public function getCurrentPolicyNodeRevision() {
  $config = $this->configFactory
    ->get('eu_cookie_compliance.settings');
  $cookie_policy_link = $config
    ->get('popup_link');
  $cookie_policy_drupal_path = \Drupal::service('path_alias.manager')
    ->getPathByAlias($cookie_policy_link, \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId());
  if (substr($cookie_policy_drupal_path, 0, 6) === '/node/') {
    $node_id = explode('/', $cookie_policy_drupal_path)[2];

    /** @var \Drupal\node\Entity\Node $node */
    $node = \Drupal::entityTypeManager()
      ->getStorage('node')
      ->load($node_id);

    // Ensure the node has been loaded before accessing any properties.
    if (!$node) {
      return FALSE;
    }
    return $node
      ->getRevisionId();
  }
  return FALSE;
}