Check the grants to relations

@param BeforeNormalizationEvent $event
766294
public function onBeforeNormalization(BeforeNormalizationEvent $event): void
    {
        $resource = $event->getResource();

        if (!$resource instanceof RelatedResourceInterface) {
            return;
        }

        $relations = $resource->getRelations();

        foreach ($relations as $relation) {
            if (!$relation instanceof SymfonyGrantedRelation) {
                continue;
            }

            if (!$this->authorizationChecker->isGranted($relation->getAttribute(), $relation->getObject())) {
                $resource->removeRelation($relation);
            }
        }
    }
203990
public function checkPermissionIsCreatable(BuildDataDefinitionEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        $container = $event->getContainer();

        if ($container->getBasicDefinition()->isCreatable()) {
            return;
        }

        $view          = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
        $modelCommands = $view->getModelCommands();

        $this->disableCommandByActionName($modelCommands, 'copy');
    }
219180
public function before($event = []) {
		$ds = ConnectionManager::getDataSource($this->connection);
		$ds->cacheSources = false;

		return true;
	}
531241
@Check
	public void checkFinalFieldInitialization(SarlEvent event) {
		final JvmGenericType inferredType = this.associations.getInferredType(event);
		if (inferredType != null) {
			checkFinalFieldInitialization(inferredType);
		}
	}
421088
public function onBefore(BeforeEvent $event)
    {
        $request = $event->getRequest();
        $options = $request->getConfig();

        $videoManagerId = isset($options['videoManagerId']) ? $options['videoManagerId'] : null;
        $token = $this->tokenManager->getToken($videoManagerId);

        if (null !== $token) {
            $request->setHeader('Authorization', sprintf(self::AUTH_BEARER, $token));
        }
    }
1031569
public function beforeValidationOnCreate(Event $event, Model $model)
    {
        if ($model instanceof ICredentialsHolder) {
            $this->createPassword($model);
        }
    }
1324723
public function beforeDelete(Delete $event)
    {
        $parent = $event->getEntity()->{$this->propertyName};
        if ($parent instanceof EntityInterface) {
            $parent->delete();
        }
    }
1144217
public function beforeSave(Event $event)
    {
        if (isset($this->_controller()->request->data['password'])) {
            $password = $this->_controller()->request->data['password'];
            $event->subject->entity['password'] = $password;
        }
    }
967187
public function beforeModeration(): bool
    {
        if (method_exists($this->owner, 'beforeModeration')) {
            if (!$this->owner->beforeModeration()) {
                return false;
            }
        }

        $event = new ModelEvent();
        $this->owner->trigger(self::EVENT_BEFORE_MODERATION, $event);

        return $event->isValid;
    }
1280368
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
    {
        if (isset($data['id'])) {
            // Unset password and password confirmation if password is empty when editing a user.
            if (isset($data['password']) && empty($data['password'])) {
                unset($data['password']);

                if (isset($data['password_confirmation'])) {
                    unset($data['password_confirmation']);
                }
            }
        }
    }
438884
public function beforePrepare(Event $event)
	{
		$command = $event['command'];
		$operation = $command->getOperation();
		$client = $command->getClient();

		if ($command->getName() !== 'updateEntity') return;
		if ($operation->getParam('collection')->getDefault() !== 'user') return;

		// Attempt to get the model's deleted at value from the array of values passed
		// to the command.
		$statusValue = false;

		if ($command->offsetExists(Model::DELETED_AT))
		{
			$statusValue = $command->offsetGet(Model::DELETED_AT);
		}
		elseif ($command->offsetExists('_kmd'))
		{
			$_kmd = array_dot($command->offsetGet('_kmd'));

			$statusField = MODEL::DELETED_AT;
			$statusField = str_replace('_kmd.', '', MODEL::DELETED_AT);

			if (array_key_exists($statusField, $_kmd))
			{
				$statusValue = $_kmd[$statusField];
			}
		}

		// Could not determine the status field.
		if ($statusValue === false)
		{
			return;
		}
		// Suspend the user.
		elseif (!is_null($statusValue))
		{
			$event->stopPropagation();

			$suspendCommand = $client->getCommand('deleteEntity', array(
				'collection' => 'user',
				'_id' => $command->offsetGet('_id'),
			));
			$suspendCommand->execute();
		}
		// Restore.
		else
		{
			$event->stopPropagation();

			$restoreCommand = $client->getCommand('restore', array(
				'_id' => $command->offsetGet('_id'),
			));
			$restoreCommand->execute();
		}
	}
465514
public function beforeFilter(\Cake\Event\Event $event)
    {
        if (isset($this->Csrf) && in_array($event->subject()->request->params['action'], ['upload'])) {
            $this->eventManager()->off($this->Csrf);
        }

        parent::beforeFilter($event);
    }
773014
public function handlePrePersistModelEvent(PrePersistModelEvent $event)
    {
        $enviroment     = $event->getEnvironment();
        $dataDefinition = $enviroment->getDataDefinition();

        if (null === ($parentDataDefinition = $enviroment->getParentDataDefinition())
            || (false === $dataDefinition->getPropertiesDefinition()->hasProperty('ptable'))
            || (false === $dataDefinition->getBasicDefinition()->isDynamicParentTable())
        ) {
            return;
        }

        $model = $event->getModel();

        $model->setProperty('ptable', $parentDataDefinition->getName());
    }
531968
public function beforeUpdate($event)
    {
        $fields = $this->fields;
        $nowDate = gmdate($this->databaseTimeFormat);
        if (!$this->isActuallyDirty()) {
            return;
        }

        if (isset($this->fields['modifiedField']) && !$this->owner->isAttributeChanged($this->fields['modifiedField'])) {
            $this->owner->{$this->fields['modifiedField']} = $nowDate;
        }
        if (isset($this->fields['modifiedByField']) && !$this->owner->isAttributeChanged($this->fields['modifiedByField'])) {
            $this->owner->{$this->fields['modifiedByField']} = self::_getUserId();
        }
    }
1085221
public function beforeFind(Event $event)
    {
        //Inject default query handlers
        $queryParameters = Hash::merge($this->getConfig('queryParameters'), [
            'sort' => [
                'callable' => [$this, '_sortParameter'],
            ],
            'include' => [
                'callable' => [$this, '_includeParameter']
            ],
            'fields' => [
                'callable' => [$this, '_fieldSetsParameter']
            ]
        ]);

        foreach ($queryParameters as $parameter => $options) {
            if (is_callable($options)) {
                $options = [
                    'callable' => $options
                ];
            }

            if (!is_callable($options['callable'])) {
                throw new \InvalidArgumentException('Invalid callable supplied for query parameter ' . $parameter);
            }

            $options['callable']($this->_request()->getQuery($parameter), $event->getSubject(), $options);
        }
    }
1342644
public function beforeSave($event) {
		if ($this->getOwner()->getIsNewRecord() && ($this->createAttribute !== null)) {
			$this->getOwner()->{$this->createAttribute} = $this->getTimestampByAttribute($this->createAttribute);
		}
		if ((!$this->getOwner()->getIsNewRecord() || $this->setUpdateOnCreate) && ($this->updateAttribute !== null)) {
			$this->getOwner()->{$this->updateAttribute} = $this->getTimestampByAttribute($this->updateAttribute);
		}
	}
1015023
public function beforeFilter(Event $event) {
		// Check security component loaded and disable it for this plugin:
		if (isset($this->Security)) {
			$this->Security->setConfig('validatePost', false);
			$this->Security->setConfig('unlockedActions', ['save']);
		}

		if (isset($this->Csrf) && $this->request->getAttribute('params')['action'] === 'save') {
			$this->getEventManager()->off($this->Csrf);
		}

		if (Configure::read('Feedback')) {
			return null;
		}

		// Throw error, config file required
		throw new NotFoundException('No Feedback config found.');
	}