Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Add graphql query.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrfritsch authored Apr 29, 2021
1 parent afbd7e5 commit 7ebec29
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 149 deletions.
8 changes: 0 additions & 8 deletions .eslintignore

This file was deleted.

94 changes: 0 additions & 94 deletions .eslintrc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ jobs:
with:
coverage: none
php-version: ${{ matrix.PHP }}
extensions: Imagick, gd, pdo_mysql

- name: Start MySql service
run: sudo /etc/init.d/mysql start
run: |
sudo /etc/init.d/mysql start
mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';"
- name: Cache composer dependencies
uses: actions/cache@v1
Expand Down
12 changes: 1 addition & 11 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ name: Check coding styles
on: [pull_request]

jobs:
eslint:
name: runner / eslint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- name: eslint
uses: reviewdog/action-eslint@v1
with:
github_token: ${{ secrets.github_token }}

phpcs:
name: runner / phpcs
runs-on: ubuntu-latest
Expand All @@ -25,6 +14,7 @@ jobs:
with:
github_token: ${{ secrets.github_token }}
level: error
filter_mode: nofilter

misspell:
name: runner / misspell
Expand Down
11 changes: 11 additions & 0 deletions graphql/ivw.base.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Ivw {
st: String
cp: String
sv: String
sc: String
co: String
mobile_cp: String
mobile_st: String
mobile_sv: String
mobile_width: String
}
3 changes: 3 additions & 0 deletions graphql/ivw.extension.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extend type Query {
ivw(path: String!): Ivw
}
2 changes: 1 addition & 1 deletion ivw_integration.tokens.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function ivw_integration_tokens($type, $tokens, array $data, array $options, Bub
elseif (isset($data['term']) && $data['term'] instanceof TermInterface) {
$lookupFrom = 'term';
}
/* @var \Drupal\ivw_integration\IvwLookupServiceInterface $lookup */
/** @var \Drupal\ivw_integration\IvwLookupServiceInterface $lookup */
$lookup = \Drupal::service('ivw_integration.lookup');
foreach ($tokens as $name => $original) {

Expand Down
18 changes: 5 additions & 13 deletions src/IvwLookupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
use Drupal\taxonomy\TermInterface;

/**
* Class IvwLookupService.
*
* @package Drupal\ivw_integration
* Service to get correct values based on the content hierarchy.
*/
class IvwLookupService implements IvwLookupServiceInterface {

Expand Down Expand Up @@ -75,11 +73,8 @@ public function byCurrentRoute($name, $parentOnly = FALSE) {
* {@inheritdoc}
*/
public function byRoute($name, RouteMatchInterface $route, $parentOnly = FALSE) {

$entity = NULL;

foreach (self::getSupportedEntityParameters() as $parameter) {
/* @var ContentEntityInterface $entity */
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
if ($entity = $route->getParameter($parameter)) {

if (is_numeric($entity)) {
Expand Down Expand Up @@ -116,12 +111,10 @@ public function getCacheTagsByCurrentRoute() {
* {@inheritdoc}
*/
public function getCacheTagsByRoute(RouteMatchInterface $route) {

$entity = NULL;
$cache_tags = [];

foreach (self::getSupportedEntityParameters() as $parameter) {
/* @var ContentEntityInterface $entity */
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
if ($entity = $route->getParameter($parameter)) {

if (is_numeric($entity)) {
Expand Down Expand Up @@ -160,12 +153,11 @@ public function getCacheTagsByRoute(RouteMatchInterface $route) {
* The gathered cache tags.
*/
private function getCacheTagsByTerm(TermInterface $term) {
/* @var \Drupal\taxonomy\TermStorage $termStorage */
/** @var \Drupal\taxonomy\TermStorageInterface $termStorage */
$termStorage = $this->entityTypeManager->getStorage('taxonomy_term');

$cache_tags = $term->getCacheTags();

/** @var \Drupal\taxonomy\TermInterface $parent */
foreach ($termStorage->loadParents($term->id()) as $parent) {
$parentCacheTags = $this->getCacheTagsByTerm($parent);
$cache_tags = Cache::mergeTags($cache_tags, $parentCacheTags);
Expand Down Expand Up @@ -299,7 +291,7 @@ protected function searchTerm($name, TermInterface $term, $parentOnly = FALSE) {
}
}

/* @var \Drupal\taxonomy\TermStorage $termStorage */
/** @var \Drupal\taxonomy\TermStorageInterface $termStorage */
$termStorage = $this->entityTypeManager->getStorage('taxonomy_term');

foreach ($termStorage->loadParents($term->id()) as $parent) {
Expand Down
4 changes: 1 addition & 3 deletions src/IvwLookupServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Drupal\taxonomy\TermInterface;

/**
* Interface IvwLookupServiceInterface.
*
* @package Drupal\ivw_integration
* Interface for the lookup service.
*/
interface IvwLookupServiceInterface {

Expand Down
56 changes: 42 additions & 14 deletions src/IvwTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Utility\Token;
use Drupal\taxonomy\TermInterface;

/**
* Class IvwTracker.
*
* @package Drupal\ivw_integration
* Provides all the IVW tracking information.
*/
class IvwTracker implements IvwTrackerInterface, CacheableDependencyInterface {

Expand Down Expand Up @@ -65,18 +65,18 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getTrackingInformation() {
public function getTrackingInformation(ContentEntityInterface $entity = NULL) {
if (!isset($this->trackingInformation)) {
$this->trackingInformation = [
'st' => $this->getSt(),
'mobile_st' => $this->getMobileSt(),
'cp' => $this->getCp(),
'sv' => $this->getSv(),
'mobile_sv' => $this->getMobileSv(),
'cp' => $this->getCp($entity),
'sv' => $this->getSv($entity),
'mobile_sv' => $this->getMobileSv($entity),
'sc' => $this->getSc(),
];
// Calculate cpm based upon cp.
// TODO: this is absolutely not generic.
// @todo This is absolutely not generic.
$this->trackingInformation['cpm'] = str_replace('D1A', 'D2A', $this->trackingInformation['cp']);
}
return $this->trackingInformation;
Expand Down Expand Up @@ -110,11 +110,21 @@ protected function getMobileSt() {
* @return string
* The value of the cp parameter.
*/
protected function getCp() {
protected function getCp(ContentEntityInterface $entity = NULL) {
$settings = $this->configFactory->get('ivw_integration.settings');
$code_template = $settings->get('code_template');

return $this->token->replace($code_template, [], ['sanitize' => FALSE]);
$data = [];
if ($entity) {
if ($entity instanceof TermInterface) {
$data['term'] = $entity;
}
else {
$data['entity'] = $entity;
}
}

return $this->token->replace($code_template, $data, ['sanitize' => FALSE]);
}

/**
Expand All @@ -124,8 +134,17 @@ protected function getCp() {
* The value of the sv parameter.
* If non is defined anywhere 'in' is returned as default.
*/
protected function getSv() {
$sv = $this->token->replace('[ivw:frabo]', [], ['sanitize' => FALSE]);
protected function getSv(ContentEntityInterface $entity = NULL) {
$data = [];
if ($entity) {
if ($entity instanceof TermInterface) {
$data['term'] = $entity;
}
else {
$data['entity'] = $entity;
}
}
$sv = $this->token->replace('[ivw:frabo]', $data, ['sanitize' => FALSE]);
return empty($sv) ? 'in' : $sv;
}

Expand All @@ -136,8 +155,17 @@ protected function getSv() {
* The value of the sv parameter.
* If non is defined anywhere 'mo' is returned as default.
*/
protected function getMobileSv() {
$sv = $this->token->replace('[ivw:frabo_mobile]', [], ['sanitize' => FALSE]);
protected function getMobileSv(ContentEntityInterface $entity = NULL) {
$data = [];
if ($entity) {
if ($entity instanceof TermInterface) {
$data['term'] = $entity;
}
else {
$data['entity'] = $entity;
}
}
$sv = $this->token->replace('[ivw:frabo_mobile]', $data, ['sanitize' => FALSE]);
return empty($sv) ? 'mo' : $sv;
}

Expand Down
8 changes: 4 additions & 4 deletions src/IvwTrackerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Drupal\ivw_integration;

use Drupal\Core\Entity\ContentEntityInterface;

/**
* Interface IvwTrackerInterface.
*
* @package Drupal\ivw_integration
* Interface for the tracking service.
*/
interface IvwTrackerInterface {

Expand All @@ -16,6 +16,6 @@ interface IvwTrackerInterface {
* Array containing 'st', 'mobile_st', 'cp', 'cpm',
* 'sv' and 'mobile_sv' parameters.
*/
public function getTrackingInformation();
public function getTrackingInformation(ContentEntityInterface $entity = NULL);

}
Loading

0 comments on commit 7ebec29

Please sign in to comment.