Skip to content
Snippets Groups Projects
Commit 3ce916b4 authored by catch's avatar catch
Browse files

Issue #3499234 by nikolay shapovalov, bbrala, nicxvan: Manually convert test modules hooks

parent f9649bc7
No related branches found
No related tags found
1 merge request!617Issue #3043725: Provide a Entity Handler for user cancelation
Pipeline #403877 failed
<?php
/**
* @file
* Contains hook implementations for testing the JSON:API module.
*/
declare(strict_types=1);
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Implements hook_jsonapi_entity_field_field_access().
*/
function jsonapi_test_field_filter_access_jsonapi_entity_field_filter_access(FieldDefinitionInterface $field_definition, AccountInterface $account) {
if ($field_definition->getName() === 'spotlight') {
return AccessResult::forbiddenIf(!$account->hasPermission('filter by spotlight field'))->cachePerPermissions();
}
if ($field_definition->getName() === 'field_test_text') {
return AccessResult::allowedIf($field_definition->getTargetEntityTypeId() === 'entity_test_with_bundle');
}
return AccessResult::neutral();
}
<?php
declare(strict_types=1);
namespace Drupal\jsonapi_test_field_filter_access\Hook;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Session\AccountInterface;
/**
* Hook implementations for jsonapi_test_field_filter_access.
*/
class JsonTestFieldFilterAccessHooks {
/**
* Implements hook_jsonapi_entity_field_filter_access().
*/
#[Hook('jsonapi_entity_field_filter_access')]
public function jsonapiEntityFieldFilterAccess(FieldDefinitionInterface $field_definition, AccountInterface $account): AccessResultInterface {
if ($field_definition->getName() === 'spotlight') {
return AccessResult::forbiddenIf(!$account->hasPermission('filter by spotlight field'))->cachePerPermissions();
}
if ($field_definition->getName() === 'field_test_text') {
return AccessResult::allowedIf($field_definition->getTargetEntityTypeId() === 'entity_test_with_bundle');
}
return AccessResult::neutral();
}
}
<?php
/**
* @file
* Provides hook implementations for Layout Builder tests.
*/
declare(strict_types=1);
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_entity_node_view().
*/
function layout_builder_extra_field_test_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
if ($display->getComponent('layout_builder_extra_field_test')) {
$build['layout_builder_extra_field_test'] = [
'#markup' => 'A new extra field.',
];
}
}
<?php
/**
* @file
* Contains.
*/
declare(strict_types=1);
use Drupal\media_library_form_overwrite_test\Form\TestAddForm;
function media_library_form_overwrite_test_media_source_info_alter(array &$sources): void {
$sources['image']['forms']['media_library_add'] = TestAddForm::class;
}
<?php
declare(strict_types=1);
namespace Drupal\media_library_form_overwrite_test\Hook;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\media_library_form_overwrite_test\Form\TestAddForm;
/**
* Hook implementations for media_library_form_overwrite_test.
*/
class MediaLibraryFormOverwriteTestHooks {
/**
* Implements hook_media_source_info_alter().
*/
#[Hook('media_source_info_alter')]
public function mediaSourceInfoAlter(array &$sources): void {
$sources['image']['forms']['media_library_add'] = TestAddForm::class;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment