Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stacks
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
stacks
Merge requests
!5
Fix dynamic property warning in controllers, phpcs cleanup
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Fix dynamic property warning in controllers, phpcs cleanup
issue/stacks-3484752:3484752-deprecated-warning-about
into
3.x
Overview
0
Commits
1
Pipelines
0
Changes
2
Open
Kyle Levitan
requested to merge
issue/stacks-3484752:3484752-deprecated-warning-about
into
3.x
6 months ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
Closes
#3484752
0
0
Merge request reports
Compare
3.x
3.x (HEAD)
and
latest version
latest version
ed8b4fc4
1 commit,
6 months ago
2 files
+
144
−
100
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/Controller/WidgetEntityAddController.php
+
99
−
75
Options
@@ -2,96 +2,120 @@
namespace
Drupal\stacks\Controller
;
use
Drupal\Core\Link
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Entity\EntityStorageInterface
;
use
Drupal\Core\Link
;
use
Drupal\Core\Url
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* Class WidgetEntityAddController.
*
* @package Drupal\stacks\Controller
*/
class
WidgetEntityAddController
extends
ControllerBase
{
public
function
__construct
(
EntityStorageInterface
$storage
,
EntityStorageInterface
$type_storage
)
{
$this
->
storage
=
$storage
;
$this
->
typeStorage
=
$type_storage
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
)
{
/** @var EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager
=
$container
->
get
(
'entity_type.manager'
);
return
new
static
(
$entity_type_manager
->
getStorage
(
'widget_entity'
),
$entity_type_manager
->
getStorage
(
'widget_entity_type'
)
);
}
/**
* The storage handler for widget entities.
*/
protected
EntityStorageInterface
$storage
;
/**
* Displays add links for available bundles/types for entity widget_entity .
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @return array
* A render array for a list of the widget_entity bundles/types that can be added or
* if there is only one type/bunlde defined for the site, the function returns the add page for that bundle/type.
*/
public
function
add
(
Request
$request
)
{
$types
=
$this
->
typeStorage
->
loadMultiple
();
if
(
$types
&&
count
(
$types
)
==
1
)
{
$type
=
reset
(
$types
);
return
$this
->
addForm
(
$type
,
$request
);
}
if
(
count
(
$types
)
===
0
)
{
return
[
'#markup'
=>
t
(
'You have not created any %bundle types yet. @link to add a new type.'
,
[
'%bundle'
=>
'Widget Entity'
,
'@link'
=>
Link
::
fromTextAndUrl
(
t
(
'Go to the type creation page'
),
Url
::
fromRoute
(
'entity.widget_entity_type.add_form'
)),
]),
];
}
return
[
'#theme'
=>
'widget_entity_content_add_list'
,
'#content'
=>
$types
];
}
/**
* The type storage handler for widget entities.
*/
protected
EntityStorageInterface
$typeStorage
;
/**
* Constructs a new WidgetEntityAddController object.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The storage handler for widget entities.
* @param \Drupal\Core\Entity\EntityStorageInterface $type_storage
* The type storage handler for widget entities.
*/
public
function
__construct
(
EntityStorageInterface
$storage
,
EntityStorageInterface
$type_storage
)
{
$this
->
storage
=
$storage
;
$this
->
typeStorage
=
$type_storage
;
}
/**
* Displays add links for available bundles/types for entity widget_entity .
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @return array
* A render array for a list of the widget_entity bundles/types that can be
* added or if there is only one type/bunlde defined for the site, the
* function returns the add page for that bundle/type.
*/
public
function
add
(
Request
$request
)
{
$types
=
$this
->
typeStorage
->
loadMultiple
();
/**
* Presents the creation form for widget_entity entities of given bundle/type.
*
* @param EntityInterface $widget_entity_type
* The custom bundle to add.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @return array
* A form array as expected by drupal_render().
*/
public
function
addForm
(
EntityInterface
$widget_entity_type
,
Request
$request
)
{
$entity
=
$this
->
storage
->
create
([
'type'
=>
$widget_entity_type
->
id
()
]);
return
$this
->
entityFormBuilder
()
->
getForm
(
$entity
);
if
(
$types
&&
\count
(
$types
)
===
1
)
{
$type
=
reset
(
$types
);
return
$this
->
addForm
(
$type
,
$request
);
}
/**
* Provides the page title for this controller.
*
* @param EntityInterface $widget_entity_type
* The custom bundle/type being added.
*
* @return string
* The page title.
*/
public
function
getAddFormTitle
(
EntityInterface
$widget_entity_type
)
{
return
t
(
'Create of bundle @label'
,
[
'@label'
=>
$widget_entity_type
->
label
()]
);
if
(
\count
(
$types
)
===
0
)
{
return
[
'#markup'
=>
t
(
'You have not created any %bundle types yet. @link to add a new type.'
,
[
'%bundle'
=>
'Widget Entity'
,
'@link'
=>
Link
::
fromTextAndUrl
(
t
(
'Go to the type creation page'
),
Url
::
fromRoute
(
'entity.widget_entity_type.add_form'
)),
]),
];
}
return
[
'#theme'
=>
'widget_entity_content_add_list'
,
'#content'
=>
$types
];
}
/**
* Presents the creation form for widget_entity entities of given bundle/type.
*
* @param \Drupal\Core\Entity\EntityInterface $widget_entity_type
* The custom bundle to add.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @return array
* A form array as expected by drupal_render().
*/
public
function
addForm
(
EntityInterface
$widget_entity_type
,
Request
$request
)
{
$entity
=
$this
->
storage
->
create
([
'type'
=>
$widget_entity_type
->
id
(),
]);
return
$this
->
entityFormBuilder
()
->
getForm
(
$entity
);
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
)
{
/** @var EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager
=
$container
->
get
(
'entity_type.manager'
);
return
new
static
(
$entity_type_manager
->
getStorage
(
'widget_entity'
),
$entity_type_manager
->
getStorage
(
'widget_entity_type'
)
);
}
/**
* Provides the page title for this controller.
*
* @param \Drupal\Core\Entity\EntityInterface $widget_entity_type
* The custom bundle/type being added.
*
* @return string
* The page title.
*/
public
function
getAddFormTitle
(
EntityInterface
$widget_entity_type
)
{
return
t
(
'Create of bundle @label'
,
[
'@label'
=>
$widget_entity_type
->
label
()]
);
}
}
Loading