Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ai
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
ai
Merge requests
!665
Resolve
#3528684
"Add processor and"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve
#3528684
"Add processor and"
issue/ai-3528684:3528684-add-processor-and
into
1.2.x
Overview
0
Commits
44
Pipelines
22
Changes
27
Merged
Artem Dmitriiev
requested to merge
issue/ai-3528684:3528684-add-processor-and
into
1.2.x
4 weeks ago
Overview
0
Commits
44
Pipelines
22
Changes
27
Expand
Closes
#3528684
0
0
Merge request reports
Compare
1.2.x
version 20
8d141e24
1 week ago
version 19
a3e0d863
1 week ago
version 18
236b7102
1 week ago
version 17
9aca1769
1 week ago
version 16
3241d516
3 weeks ago
version 15
cac1ae95
3 weeks ago
version 14
8de1d79c
3 weeks ago
version 13
02559b4f
3 weeks ago
version 12
d715ffd4
3 weeks ago
version 11
c95556f2
3 weeks ago
version 10
3cb51a2e
3 weeks ago
version 9
f4bbbbfd
3 weeks ago
version 8
27d6b6ab
3 weeks ago
version 7
5d5641b6
3 weeks ago
version 6
ee7703a8
3 weeks ago
version 5
97f0e7d6
3 weeks ago
version 4
1bebf96a
4 weeks ago
version 3
923ae7fb
4 weeks ago
version 2
15ed2893
4 weeks ago
version 1
7a1e34b6
4 weeks ago
1.2.x (base)
and
latest version
latest version
6cccb48f
44 commits,
1 week ago
version 20
8d141e24
43 commits,
1 week ago
version 19
a3e0d863
42 commits,
1 week ago
version 18
236b7102
41 commits,
1 week ago
version 17
9aca1769
40 commits,
1 week ago
version 16
3241d516
20 commits,
3 weeks ago
version 15
cac1ae95
19 commits,
3 weeks ago
version 14
8de1d79c
18 commits,
3 weeks ago
version 13
02559b4f
17 commits,
3 weeks ago
version 12
d715ffd4
16 commits,
3 weeks ago
version 11
c95556f2
15 commits,
3 weeks ago
version 10
3cb51a2e
14 commits,
3 weeks ago
version 9
f4bbbbfd
13 commits,
3 weeks ago
version 8
27d6b6ab
12 commits,
3 weeks ago
version 7
5d5641b6
10 commits,
3 weeks ago
version 6
ee7703a8
9 commits,
3 weeks ago
version 5
97f0e7d6
8 commits,
3 weeks ago
version 4
1bebf96a
7 commits,
4 weeks ago
version 3
923ae7fb
6 commits,
4 weeks ago
version 2
15ed2893
5 commits,
4 weeks ago
version 1
7a1e34b6
3 commits,
4 weeks ago
27 files
+
2059
−
285
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
27
Search (e.g. *.vue) (Ctrl+P)
modules/ai_automators/src/Plugin/AiAutomatorProcess/FieldWidgetProcessing.php
0 → 100644
+
107
−
0
Options
<?php
namespace
Drupal\ai_automators\Plugin\AiAutomatorProcess
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\Core\Field\FieldDefinitionInterface
;
use
Drupal\Core\Logger\LoggerChannelFactoryInterface
;
use
Drupal\Core\Messenger\MessengerInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\StringTranslation\TranslatableMarkup
;
use
Drupal\ai_automators
\AiAutomatorRuleRunner
;
use
Drupal\ai_automators
\Attribute\AiAutomatorProcessRule
;
use
Drupal\ai_automators
\Exceptions\AiAutomatorRequestErrorException
;
use
Drupal\ai_automators
\Exceptions\AiAutomatorResponseErrorException
;
use
Drupal\ai_automators
\Exceptions\AiAutomatorRuleNotFoundException
;
use
Drupal\ai_automators
\PluginInterfaces\AiAutomatorFieldProcessInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* The field widget processor.
*/
#
[
AiAutomatorProcessRule
(
id
:
'field_widget_actions'
,
title
:
new
TranslatableMarkup
(
'Field Widget'
),
description
:
new
TranslatableMarkup
(
'Processes the widget when the user takes action. This will not save the entity, only add values to the form.'
),
)]
class
FieldWidgetProcessing
implements
AiAutomatorFieldProcessInterface
,
ContainerFactoryPluginInterface
{
/**
* Constructor.
*/
final
public
function
__construct
(
protected
AiAutomatorRuleRunner
$aiRunner
,
protected
LoggerChannelFactoryInterface
$loggerFactory
,
protected
MessengerInterface
$messenger
,
protected
ModuleHandlerInterface
$moduleHandler
,
)
{
}
/**
* {@inheritDoc}
*/
final
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$container
->
get
(
'ai_automator.rule_runner'
),
$container
->
get
(
'logger.factory'
),
$container
->
get
(
'messenger'
),
$container
->
get
(
'module_handler'
)
);
}
/**
* {@inheritDoc}
*/
public
function
modify
(
EntityInterface
$entity
,
FieldDefinitionInterface
$fieldDefinition
,
array
$automatorConfig
)
{
try
{
return
$this
->
aiRunner
->
generateResponse
(
$entity
,
$fieldDefinition
,
$automatorConfig
);
}
catch
(
AiAutomatorRuleNotFoundException
$e
)
{
$this
->
loggerFactory
->
get
(
'ai_automator'
)
->
warning
(
'A rule was not found, message %message'
,
[
'%message'
=>
$e
->
getMessage
(),
]);
}
catch
(
AiAutomatorRequestErrorException
$e
)
{
$this
->
loggerFactory
->
get
(
'ai_automator'
)
->
warning
(
'A request error happened, message %message'
,
[
'%message'
=>
$e
->
getMessage
(),
]);
}
catch
(
AiAutomatorResponseErrorException
$e
)
{
$this
->
loggerFactory
->
get
(
'ai_automator'
)
->
warning
(
'A response was not correct, message %message'
,
[
'%message'
=>
$e
->
getMessage
(),
]);
}
catch
(
\Exception
$e
)
{
$this
->
loggerFactory
->
get
(
'ai_automator'
)
->
warning
(
'A general error happened why trying to interpolate, message %message'
,
[
'%message'
=>
$e
->
getMessage
(),
]);
}
$this
->
messenger
->
addWarning
(
$e
->
getMessage
());
return
FALSE
;
}
/**
* {@inheritDoc}
*/
public
function
preProcessing
(
EntityInterface
$entity
)
{
// We do not need to do anything since we are not saving the entity.
}
/**
* {@inheritDoc}
*/
public
function
postProcessing
(
EntityInterface
$entity
)
{
// We do not need to do anything since we are not saving the entity.
}
/**
* {@inheritDoc}
*/
public
function
processorIsAllowed
(
EntityInterface
$entity
,
FieldDefinitionInterface
$fieldDefinition
)
{
// Only is available if the Form Widget Actions module is enabled.
return
$this
->
moduleHandler
->
moduleExists
(
'field_widget_actions'
);
}
}
Loading