查询联系表单实体
\Drupal::entityTypeManager()
->getStorage('contact_form')
->loadMultiple();
=> [
"feedback" => Drupal\contact\Entity\ContactForm {#3213},
"personal" => Drupal\contact\Entity\ContactForm {#3994},
]
联系表格计数
\Drupal::entityTypeManager()
->getStorage('contact_form')
->getQuery()
->count()
->execute();
=> 2
关于你的最后一个问题;解决此问题的一种方法是子类化ContactFormListBuilder
并覆盖其默认render()
逻辑:
路由 YAML
my_module.custom_contact_form_list:
path: '/admin/foo/custom-contact-form-listing'
defaults:
_controller: '\Drupal\my_module\Controller\ContactFormListController::listing'
_title: 'A custom contact form listing view'
requirements:
_permission: 'administer contact forms'
上市控制器
<?php
namespace Drupal\my_module\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\my_module\CustomContactFormListBuilder;
/**
* Class ContactFormListController.
*
* @package Drupal\my_module\Controller
*/
class ContactFormListController extends ControllerBase {
/**
* Provides a custom listing page for contact forms.
*
* @return array
* A render array as expected by
* \Drupal\Core\Render\RendererInterface::render().
*/
public function listing() {
$definition = $this->entityTypeManager()->getDefinition('contact_form');
return $this
->entityTypeManager()
->createHandlerInstance(CustomContactFormListBuilder::class, $definition)
->render();
}
}
列表生成器类
<?php
namespace Drupal\my_module;
use Drupal\contact\ContactFormListBuilder;
/**
* Class CustomContactFormListBuilder.
*
* @package Drupal\my_module
*/
class CustomContactFormListBuilder extends ContactFormListBuilder {
/**
* {@inheritdoc}
*/
public function render() {
return parent::render(); // TODO: Change the autogenerated stub
}
}