Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 20 additions & 98 deletions .github/workflows/build-3.x.yml
Original file line number Diff line number Diff line change
@@ -1,115 +1,37 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the 8.x branch
push:
branches: [ 3.x ]
pull_request:
branches: [ 3.x ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
continue-on-error: false
strategy:
fail-fast: false
matrix:
php-versions: ["8.1", "8.2", "8.3"]
drupal-version: ["10.3.x", "10.4.x-dev", "11.0.x"]
exclude:
- drupal-version: "11.0.x"
php-versions: "8.1"
- drupal-version: "11.0.x"
php-versions: "8.2"
env:
DRUPAL_VERSION: ${{ matrix.drupal-version }}
SCRIPT_DIR: ${{ github.workspace }}/islandora_ci
DRUPAL_DIR: /opt/drupal
DRUPAL_WEB_ROOT: /opt/drupal/web
PHPUNIT_FILE: ${{ github.workspace }}/build_dir/phpunit.xml

services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: drupal
ports:
- 3306:3306
activemq:
image: webcenter/activemq:5.14.3
ports:
- 8161:8161
- 61616:61616
- 61613:61613

php-versions: ["8.3", "8.4"]
drupal-version: ["10.5", "10.6", "11.2", "11.3"]
name: PHP ${{ matrix.php-versions }} | drupal ${{ matrix.drupal-version }}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
uses: actions/checkout@v4
with:
path: build_dir

- name: Checkout islandora_ci
uses: actions/checkout@v4
with:
repository: islandora/islandora_ci
ref: github-actions
path: islandora_ci

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer:v2

- name: Setup Mysql client
run: |
sudo apt-get update
sudo apt-get install -y mysql-client
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Setup Drupal
run: |
mkdir $DRUPAL_DIR
$SCRIPT_DIR/travis_setup_drupal.sh
cd $DRUPAL_DIR
chmod -R u+w web/sites/default
mkdir -p web/sites/simpletest/browser_output

- name: Setup composer paths
run: |
git -C "$GITHUB_WORKSPACE/build_dir" checkout -b github-testing
cd $DRUPAL_DIR
composer config repositories.local path "$GITHUB_WORKSPACE/build_dir"
composer config minimum-stability dev
composer require "drupal/jsonld:dev-github-testing as dev-3.x" --prefer-source -W

- name: Install modules
run: |
cd $DRUPAL_DIR/web
drush --uri=127.0.0.1:8282 en -y user jsonld

- name: Copy PHPunit file
run: cp $PHPUNIT_FILE $DRUPAL_DIR/web/core/phpunit.xml

- name: Test scripts
run: $SCRIPT_DIR/travis_scripts.sh

# Unit test config is defined in the module's phpunit.xml file.
- name: PHPUNIT tests
run: |
cd $DRUPAL_DIR/web/core
$DRUPAL_DIR/vendor/bin/phpunit --debug
docker run \
--rm \
--name drupal \
--hostname drupal \
--volume $(pwd):/var/www/drupal/web/modules/contrib/$ENABLE_MODULES:ro \
--env ENABLE_MODULES \
ghcr.io/islandora/ci:${{ matrix.drupal-version }}-php${{ matrix.php-versions }}
env:
ENABLE_MODULES: jsonld
2 changes: 1 addition & 1 deletion jsonld.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
arguments: ['jsonld']
jsonld.contextgenerator:
class: Drupal\jsonld\ContextGenerator\JsonldContextGenerator
arguments: ['@entity_field.manager','@entity_type.bundle.info','@entity_type.manager', '@cache.default', '@logger.channel.jsonld']
arguments: ['@entity_field.manager','@entity_type.bundle.info','@entity_type.manager', '@cache.default', '@logger.channel.jsonld', '@module_handler']
jsonld.normalizer_utils:
class: Drupal\jsonld\Utils\JsonldNormalizerUtils
arguments: ['@config.factory', '@language_manager', '@router.route_provider']
29 changes: 21 additions & 8 deletions src/ContextGenerator/JsonldContextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\rdf\Entity\RdfMapping;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\rdf\RdfMappingInterface;
use Psr\Log\LoggerInterface;

Expand All @@ -21,6 +22,8 @@
*/
class JsonldContextGenerator implements JsonldContextGeneratorInterface {

use StringTranslationTrait;

/**
* Constant Naming convention used to prefix name cache bins($cid)
*/
Expand Down Expand Up @@ -68,6 +71,13 @@ class JsonldContextGenerator implements JsonldContextGeneratorInterface {
*/
protected $logger;

/**
* Injected Module Handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;

/**
* Cached field type mappings.
*
Expand All @@ -88,13 +98,16 @@ class JsonldContextGenerator implements JsonldContextGeneratorInterface {
* Caching Backend.
* @param \Psr\Log\LoggerInterface $logger_channel
* Our Logging Channel.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(EntityFieldManagerInterface $entity_field_manager, EntityTypeBundleInfoInterface $bundle_info, EntityTypeManagerInterface $entity_manager, CacheBackendInterface $cache_backend, LoggerInterface $logger_channel) {
public function __construct(EntityFieldManagerInterface $entity_field_manager, EntityTypeBundleInfoInterface $bundle_info, EntityTypeManagerInterface $entity_manager, CacheBackendInterface $cache_backend, LoggerInterface $logger_channel, ModuleHandlerInterface $module_handler) {
$this->entityFieldManager = $entity_field_manager;
$this->entityTypeManager = $entity_manager;
$this->bundleInfo = $bundle_info;
$this->cache = $cache_backend;
$this->logger = $logger_channel;
$this->moduleHandler = $module_handler;
}

/**
Expand All @@ -105,7 +118,7 @@ public function getContext($ids) {
$cache = $this->cache->get($cid);
$data = '';
if (!$cache) {
$rdfMapping = RdfMapping::load($ids);
$rdfMapping = $this->entityTypeManager->getStorage('rdf_mapping')->load($ids);
// Our whole chain of exceptions will never happen
// because RdfMapping:load returns NULL on non existance
// Which forces me to check for it
Expand All @@ -115,7 +128,7 @@ public function getContext($ids) {
$data = $this->writeCache($rdfMapping, $cid);
}
else {
$msg = t("Can't generate JSON-LD Context for @ids without RDF Mapping present.",
$msg = $this->t("Can't generate JSON-LD Context for @ids without RDF Mapping present.",
['@ids' => $ids]);
$this->logger->warning("@msg",
[
Expand Down Expand Up @@ -154,8 +167,8 @@ public function generateContext(RdfMappingInterface $rdfMapping) {
// This only generates an Exception if there is an
// rdfmapping object but has no rdf:type.
if (empty($bundle_rdf_mappings['types'])) {
$msg = t("Can't generate JSON-LD Context without at least one rdf:type for Entity type @entity_type, Bundle @bundle_name combo.",
['@entity_type' => $entity_type_id, ' @bundle_name' => $bundle]);
$msg = $this->t("Can't generate JSON-LD Context without at least one rdf:type for Entity type @entity_type, Bundle @bundle_name combo.",
['@entity_type' => $entity_type_id, '@bundle_name' => $bundle]);
$this->logger->warning("@msg",
[
'@msg' => $msg,
Expand Down Expand Up @@ -333,11 +346,11 @@ protected function getTermContextFromField($field_type) {
// yet for this instance.
if (empty($this->fieldMappings)) {
// Cribbed from rdf module's rdf_get_namespaces.
\Drupal::moduleHandler()->invokeAllWith(self::FIELD_MAPPPINGS_HOOK, function (callable $hook, string $module) {
$this->moduleHandler->invokeAllWith(self::FIELD_MAPPPINGS_HOOK, function (callable $hook, string $module) {
foreach ($hook() as $field => $mapping) {
if (array_key_exists($field, $this->fieldMappings)) {
$this->logger->warning(
t('Tried to map @field_type to @new_type, but @field_type is already mapped to @orig_type.', [
$this->t('Tried to map @field_type to @new_type, but @field_type is already mapped to @orig_type.', [
'@field_type' => $field,
'@new_type' => $mapping['@type'],
'@orig_type' => $this->fieldMappings[$field]['@type'],
Expand Down
3 changes: 1 addition & 2 deletions src/Controller/JsonldContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerBase;
use Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface;
use Drupal\rdf\Entity\RdfMapping;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -75,7 +74,7 @@ public function content($entity_type, $bundle, Request $request) {
// For now deal with Cache dependencies manually.
$meta = new CacheableMetadata();
$meta->setCacheContexts(['user.permissions', 'ip', 'url']);
$meta->setCacheTags(RdfMapping::load("$entity_type.$bundle")->getCacheTags());
$meta->setCacheTags($this->entityTypeManager()->getStorage('rdf_mapping')->load("$entity_type.$bundle")->getCacheTags());
$meta->setCacheMaxAge(Cache::PERMANENT);
$response->addCacheableDependency($meta);
}
Expand Down
1 change: 0 additions & 1 deletion src/Normalizer/EntityReferenceItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function normalize($field_item, $format = NULL, array $context = []): arr
// If the parent entity passed in a langcode, unset it before normalizing
// the target entity. Otherwise, untranslatable fields of the target entity
// will include the langcode.
$langcode = $context['langcode'] ?? NULL;
unset($context['langcode']);
// Limiting to uuid makes sure that we only get one child from base entity
// if not we could end traversing forever since there is no way
Expand Down
5 changes: 3 additions & 2 deletions tests/src/Kernel/JsonldContextGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public function setUp() :void {
$this->container->get('entity_type.bundle.info'),
$this->container->get('entity_type.manager'),
$this->container->get('cache.default'),
$this->container->get('logger.channel.jsonld')
$this->container->get('logger.channel.jsonld'),
$this->container->get('module_handler')
);

}
Expand Down Expand Up @@ -127,7 +128,7 @@ public function testGenerateContextException() {
// This should throw the expected Exception.
$newEntity = $this->createContentType();
$rdfMapping = rdf_get_mapping('entity_test', $newEntity->id());
$this->theJsonldContextGenerator->getContext('entity_test.' . $newEntity->id());
$this->theJsonldContextGenerator->generateContext($rdfMapping);
}

/**
Expand Down