Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inline_entity_form
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
inline_entity_form
Merge requests
!83
Issues
#3371257
and
#3367002
: Add support for the menu entity.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issues
#3371257
and
#3367002
: Add support for the menu entity.
issue/inline_entity_form-3371257:3371257-add-support-for
into
2.0.x
Overview
4
Commits
2
Pipelines
0
Changes
5
All threads resolved!
Hide all comments
Merged
Davyd Burianuvatyi
requested to merge
issue/inline_entity_form-3371257:3371257-add-support-for
into
2.0.x
1 year ago
Overview
4
Commits
2
Pipelines
0
Changes
5
Expand
Closes
#3367002
and
#3371257
Edited
1 year ago
by
Andrii Podanenko
0
0
Merge request reports
Compare
2.0.x
version 1
76caf373
1 year ago
2.0.x (base)
and
latest version
latest version
3e937cc9
2 commits,
1 year ago
version 1
76caf373
1 commit,
1 year ago
5 files
+
290
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
modules/inline_entity_menu_form/src/Plugin/Field/FieldWidget/InlineEntityFormMenu.php
0 → 100644
+
95
−
0
Options
<?php
namespace
Drupal\inline_entity_menu_form\Plugin\Field\FieldWidget
;
use
Drupal\Component\Serialization\Json
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Field\FieldDefinitionInterface
;
use
Drupal\Core\Field\FieldItemListInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Url
;
use
Drupal\inline_entity_form
\Plugin\Field\FieldWidget\InlineEntityFormComplex
;
/**
* Menu entity inline widget.
*
* @FieldWidget(
* id = "inline_entity_form_menu",
* label = @Translation("Inline entity form - Menu"),
* field_types = {
* "entity_reference",
* "entity_reference_revisions",
* },
* multiple_values = true
* )
*/
class
InlineEntityFormMenu
extends
InlineEntityFormComplex
{
/**
* {@inheritdoc}
*/
public
function
settingsForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$element
=
parent
::
settingsForm
(
$form
,
$form_state
);
$element
[
'form_mode'
]
=
[
'#type'
=>
'select'
,
'#title'
=>
$this
->
t
(
'Form mode'
),
'#default_value'
=>
'edit'
,
'#options'
=>
[
'edit'
=>
'Edit'
],
'#required'
=>
TRUE
,
];
return
$element
;
}
/**
* {@inheritdoc}
*/
protected
function
getInlineEntityForm
(
$operation
,
$bundle
,
$langcode
,
$delta
,
array
$parents
,
EntityInterface
$entity
=
NULL
)
{
$element
=
parent
::
getInlineEntityForm
(
$operation
,
$bundle
,
$langcode
,
$delta
,
$parents
,
$entity
);
$element
[
'#save_entity'
]
=
TRUE
;
return
$element
;
}
/**
* {@inheritdoc}
*/
public
static
function
isApplicable
(
FieldDefinitionInterface
$field_definition
)
{
return
$field_definition
->
getFieldStorageDefinition
()
->
getSetting
(
'target_type'
)
===
'menu'
;
}
/**
* {@inheritdoc}
*/
public
function
formElement
(
FieldItemListInterface
$items
,
$delta
,
array
$element
,
array
&
$form
,
FormStateInterface
$form_state
)
{
$element
=
parent
::
formElement
(
$items
,
$delta
,
$element
,
$form
,
$form_state
);
$entities
=
$form_state
->
get
([
'inline_entity_form'
,
$this
->
getIefId
(),
'entities'
,
]);
foreach
(
$entities
as
$key
=>
$entity
)
{
$row
=
&
$element
[
'entities'
][
$key
];
$title
=
$this
->
t
(
'Edit Links'
);
$row
[
'actions'
][
'ief_entity_menu'
]
=
[
'#type'
=>
'link'
,
'#title'
=>
$title
,
'#url'
=>
Url
::
fromRoute
(
'inline_entity_menu_form.menu.edit_links_form'
,
[
'menu'
=>
$entity
[
'entity'
]
->
id
()]),
'#attributes'
=>
[
'class'
=>
[
'use-ajax'
,
'btn-primary'
],
'data-dialog-type'
=>
'modal'
,
'data-dialog-options'
=>
Json
::
encode
([
'width'
=>
700
,
'closeOnEscape'
=>
TRUE
,
'title'
=>
$title
,
'autoResize'
=>
TRUE
,
]),
],
];
}
return
$element
;
}
}
Loading