Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
entity_references_map
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
entity_references_map
Merge requests
!21
#3388843
created global entity type mapping disabling functionality
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
#3388843
created global entity type mapping disabling functionality
issue/3259790-3388843:3388843-entity-global-config
into
main
Overview
5
Commits
4
Pipelines
0
Changes
7
All threads resolved!
Hide all comments
Merged
#3388843 created global entity type mapping disabling functionality
Pavlo Radyvonik
requested to merge
issue/3259790-3388843:3388843-entity-global-config
into
main
Sep 21, 2023
Overview
5
Commits
4
Pipelines
0
Changes
7
All threads resolved!
Hide all comments
Closes
#3388843
0
0
Merge request reports
Compare
main
version 3
e3dd290f
Sep 26, 2023
version 2
e4ef0ced
Sep 21, 2023
version 1
36439fc0
Sep 21, 2023
main (base)
and
latest version
latest version
e6dbe559
4 commits,
Sep 26, 2023
version 3
e3dd290f
3 commits,
Sep 26, 2023
version 2
e4ef0ced
2 commits,
Sep 21, 2023
version 1
36439fc0
1 commit,
Sep 21, 2023
7 files
+
153
−
20
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
src/Form/EntityTypeDisableForm.php
0 → 100644
+
116
−
0
View file @ e6dbe559
Edit in single-file editor
Open in Web IDE
<?php
namespace
Drupal\entity_references_map\Form
;
use
Drupal\Component\Utility\NestedArray
;
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\Core\Entity\ContentEntityTypeInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Form\ConfigFormBase
;
use
Drupal\Core\Form\FormStateInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Entity type disable configuration form.
*/
class
EntityTypeDisableForm
extends
ConfigFormBase
{
public
const
CONFIG_NAME
=
'entity_references_map.config'
;
/**
* The EntityTypeManager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
EntityTypeManagerInterface
$entityTypeManager
;
/**
* Constructs EntityTypeDisableForm instance.
*/
public
function
__construct
(
ConfigFactoryInterface
$config_factory
,
EntityTypeManagerInterface
$entityTypeManager
)
{
parent
::
__construct
(
$config_factory
);
$this
->
entityTypeManager
=
$entityTypeManager
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
):
EntityTypeDisableForm
|
ConfigFormBase
|
static
{
return
new
static
(
$container
->
get
(
'config.factory'
),
$container
->
get
(
'entity_type.manager'
)
);
}
/**
* {@inheritdoc}
*/
protected
function
getEditableConfigNames
():
array
{
return
[
self
::
CONFIG_NAME
];
}
/**
* {@inheritdoc}
*/
public
function
getFormId
():
string
{
return
'entity_references_map.entity_type_disable_form'
;
}
/**
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
):
array
{
$config_data
=
$this
->
config
(
self
::
CONFIG_NAME
)
->
get
();
$entity_options_array
=
[];
foreach
(
$this
->
entityTypesList
()
as
$entity_type
)
{
$entity_options_array
[
$entity_type
->
id
()]
=
$entity_type
->
getLabel
();
}
$form
[
'entities'
]
=
[
'#type'
=>
'checkboxes'
,
'#title'
=>
$this
->
t
(
'Excluded Entity Types from Entity References Map'
),
'#options'
=>
$entity_options_array
,
'#description'
=>
$this
->
t
(
'Selected entity types will be excluded from mapping.'
),
'#default_value'
=>
NestedArray
::
getValue
(
$config_data
,
[
'disabled_entity_types'
,
]),
];
return
parent
::
buildForm
(
$form
,
$form_state
);
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
):
void
{
$values
=
$form_state
->
getValue
(
'entities'
);
$config
=
$this
->
config
(
self
::
CONFIG_NAME
);
foreach
(
$values
as
$key
=>
$value
)
{
if
(
!
empty
(
$value
))
{
$config
->
set
(
"disabled_entity_types.
$key
"
,
$value
);
}
else
{
$config
->
clear
(
"disabled_entity_types.
$key
"
);
}
}
$config
->
save
();
parent
::
submitForm
(
$form
,
$form_state
);
}
/**
* Returns list of entity types available on the site.
*/
public
function
entityTypesList
():
array
{
$entity_types
=
$this
->
entityTypeManager
->
getDefinitions
();
return
array_filter
(
$entity_types
,
static
function
(
$entity_type
)
{
return
$entity_type
instanceof
ContentEntityTypeInterface
;
});
}
}
Loading