Skip to content
Snippets Groups Projects
Commit d13eacc6 authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-5666: cleaning up code

parent c7479ffd
No related branches found
No related tags found
1 merge request!250ISTWCMS-5666 Add a feed for content type use, matching WCMS 2
...@@ -14,7 +14,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; ...@@ -14,7 +14,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
/** /**
* Provides route responses for the Example module. * Provides route responses for the Example module.
*/ */
class ContentTypeUseController extends ControllerBase { class ContentTypeUsePage extends ControllerBase {
/** /**
* Entity type manager from the core. * Entity type manager from the core.
* *
...@@ -77,8 +77,9 @@ class ContentTypeUseController extends ControllerBase { ...@@ -77,8 +77,9 @@ class ContentTypeUseController extends ControllerBase {
} }
// Call to the service to get the count of content types used. // Call to the service to get the count of content types used.
$options = $this->uwService->getContentTypeUsage($cts); $list = $this->uwService->getContentTypeUsage($cts, TRUE);
return new JsonResponse($options);
return new JsonResponse($list);
} }
} }
...@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; ...@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\simplify_menu\MenuItems; use Drupal\simplify_menu\MenuItems;
use Drupal\path_alias\AliasManager; use Drupal\path_alias\AliasManager;
use phpDocumentor\Reflection\Types\False_;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
/** /**
...@@ -543,7 +544,10 @@ class UWService implements UWServiceInterface { ...@@ -543,7 +544,10 @@ class UWService implements UWServiceInterface {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getContentTypeUsage(array $content_types): array { public function getContentTypeUsage(
array $content_types,
bool $show_null_content_types = FALSE
): array {
// Node content types array. // Node content types array.
$list = []; $list = [];
...@@ -560,14 +564,18 @@ class UWService implements UWServiceInterface { ...@@ -560,14 +564,18 @@ class UWService implements UWServiceInterface {
// If there are no nodes of the content type, // If there are no nodes of the content type,
// break out of this iteration, as we do not // break out of this iteration, as we do not
// want to display no nodes. // want to display no nodes, however if flag
if ($total == 0) { // is set to show null nodes we will show them.
if ($total == 0 && !$show_null_content_types) {
continue; continue;
} }
// Load the content type, we need to use current as this // Load the content type, we need to use current as this
// will load multiple, current will load the first entry. // will load multiple, current will load the first entry.
$content_type = current($this->entityTypeManager->getStorage('node_type')->loadByProperties(['type' => $ct])); $content_type = current(
$this->entityTypeManager->getStorage('node_type')
->loadByProperties(['type' => $ct])
);
// Add the condition of published to query. // Add the condition of published to query.
$query->condition('status', 1); $query->condition('status', 1);
...@@ -583,6 +591,7 @@ class UWService implements UWServiceInterface { ...@@ -583,6 +591,7 @@ class UWService implements UWServiceInterface {
'unpublished' => $total - $published, 'unpublished' => $total - $published,
]; ];
} }
return $list; return $list;
} }
......
...@@ -207,6 +207,6 @@ interface UWServiceInterface { ...@@ -207,6 +207,6 @@ interface UWServiceInterface {
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/ */
public function getContentTypeUsage(array $content_types): array; public function getContentTypeUsage(array $content_types, bool $show_null_content_types): array;
} }
...@@ -27,10 +27,10 @@ uw_ldap.view_user: ...@@ -27,10 +27,10 @@ uw_ldap.view_user:
username: NULL username: NULL
requirements: requirements:
_permission: 'administer site configuration' _permission: 'administer site configuration'
uw_cfg_common.Controller: uw_cfg_common.content_type_usage_page:
path: '/content_type_use.json' path: '/content_type_use.json'
defaults: defaults:
_controller: '\Drupal\uw_cfg_common\Controller\ContentTypeUseController::contentTypeUse' _controller: '\Drupal\uw_cfg_common\Controller\ContentTypeUsePage::contentTypeUse'
_title: 'Content type Use' _title: 'Content type Use'
requirements: requirements:
_permission: 'access content' _permission: 'access content'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment