本文整理汇总了PHP中Drupal\Core\Extension\ModuleHandlerInterface::getImplementations方法的典型用法代码示例。如果您正苦于以下问题:PHP ModuleHandlerInterface::getImplementations方法的具体用法?PHP ModuleHandlerInterface::getImplementations怎么用?PHP ModuleHandlerInterface::getImplementations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Extension\ModuleHandlerInterface
的用法示例。
在下文中一共展示了ModuleHandlerInterface::getImplementations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$modules = $input->getArgument('module');
if (!$this->lock->acquire('cron', 900.0)) {
$io->warning($this->trans('commands.cron.execute.messages.lock'));
return 1;
}
if (in_array('all', $modules)) {
$modules = $this->moduleHandler->getImplementations('cron');
}
foreach ($modules as $module) {
if (!$this->moduleHandler->implementsHook($module, 'cron')) {
$io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module));
continue;
}
try {
$io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module));
$this->moduleHandler->invoke($module, 'cron');
} catch (\Exception $e) {
watchdog_exception('cron', $e);
$io->error($e->getMessage());
}
}
$this->state->set('system.cron_last', REQUEST_TIME);
$this->lock->release('cron');
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
$io->success($this->trans('commands.cron.execute.messages.success'));
return 0;
}
示例2: listTopics
/**
* {@inheritdoc}
*/
public function listTopics()
{
$topics = [];
foreach ($this->moduleHandler->getImplementations('help') as $module) {
$title = $this->moduleHandler->getName($module);
$topics[$title] = Link::createFromRoute($title, 'help.page', ['name' => $module]);
}
// Sort topics by title, which is the array key above.
ksort($topics);
return $topics;
}
示例3: getDefinitions
/**
* Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
*/
public function getDefinitions()
{
$definitions = array();
foreach ($this->moduleHandler->getImplementations($this->hook) as $module) {
$result = $this->moduleHandler->invoke($module, $this->hook);
foreach ($result as $plugin_id => $definition) {
$definition['module'] = $module;
$definitions[$plugin_id] = $definition;
}
}
return $definitions;
}
示例4: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
$this->moduleHandler->getImplementations('entity_type_build')->willReturn([]);
$this->moduleHandler->alter('entity_type', Argument::type('array'))->willReturn(NULL);
$this->cacheBackend = $this->prophesize(CacheBackendInterface::class);
$this->translationManager = $this->prophesize(TranslationInterface::class);
$this->entityTypeManager = new TestEntityTypeManager(new \ArrayObject(), $this->moduleHandler->reveal(), $this->cacheBackend->reveal(), $this->translationManager->reveal(), $this->getClassResolverStub());
$this->discovery = $this->prophesize(DiscoveryInterface::class);
$this->entityTypeManager->setDiscovery($this->discovery->reveal());
}
示例5: getData
/**
* Gets all data invoked by hook_views_data().
*
* This is requested from the cache before being rebuilt.
*
* @return array
* An array of all data.
*/
protected function getData()
{
$this->fullyLoaded = TRUE;
if ($data = $this->cacheGet($this->baseCid)) {
return $data->data;
} else {
$modules = $this->moduleHandler->getImplementations('views_data');
$data = [];
foreach ($modules as $module) {
$views_data = $this->moduleHandler->invoke($module, 'views_data');
// Set the provider key for each base table.
foreach ($views_data as &$table) {
if (isset($table['table']) && !isset($table['table']['provider'])) {
$table['table']['provider'] = $module;
}
}
$data = NestedArray::mergeDeep($data, $views_data);
}
$this->moduleHandler->alter('views_data', $data);
$this->processEntityTypes($data);
// Keep a record with all data.
$this->cacheSet($this->baseCid, $data);
return $data;
}
}
示例6: isReserved
/**
* {@inheritdoc}
*/
public function isReserved($alias, $source, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED)
{
// Check if this alias already exists.
if ($existing_source = $this->aliasManager->getPathByAlias($alias, $langcode)) {
if ($existing_source != $alias) {
// If it is an alias for the provided source, it is allowed to keep using
// it. If not, then it is reserved.
return $existing_source != $source;
}
}
// Then check if there is a route with the same path.
if ($this->isRoute($alias)) {
return TRUE;
}
// Finally check if any other modules have reserved the alias.
$args = array($alias, $source, $langcode);
$implementations = $this->moduleHandler->getImplementations('pathauto_is_alias_reserved');
foreach ($implementations as $module) {
$result = $this->moduleHandler->invoke($module, 'pathauto_is_alias_reserved', $args);
if (!empty($result)) {
// As soon as the first module says that an alias is in fact reserved,
// then there is no point in checking the rest of the modules.
return TRUE;
}
}
return FALSE;
}
示例7: getModulesList
/**
* Returns a list with all modules which sends emails.
*
* Currently this is evaluated by the hook_mail implementation.
*
* @return array
* Associative array with all modules which sends emails:
* - module: label
*/
protected function getModulesList()
{
$list = array('none' => $this->t('-- Select --'));
foreach ($this->moduleHandler->getImplementations('mail') as $module) {
$list[$module] = ucfirst($module);
}
return $list;
}
示例8: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state)
{
$role_names = array();
$role_permissions = array();
foreach ($this->getRoles() as $role_name => $role) {
// Retrieve role names for columns.
$role_names[$role_name] = String::checkPlain($role->label());
// Fetch permissions for the roles.
$role_permissions[$role_name] = $role->getPermissions();
}
// Store $role_names for use when saving the data.
$form['role_names'] = array('#type' => 'value', '#value' => $role_names);
// Render role/permission overview:
$options = array();
$module_info = system_rebuild_module_data();
$hide_descriptions = system_admin_compact_mode();
// Get a list of all the modules implementing a hook_permission() and sort by
// display name.
$modules = array();
foreach ($this->moduleHandler->getImplementations('permission') as $module) {
$modules[$module] = $module_info[$module]->info['name'];
}
asort($modules);
$form['system_compact_link'] = array('#theme' => 'system_compact_link');
$form['permissions'] = array('#type' => 'table', '#header' => array($this->t('Permission')), '#id' => 'permissions', '#sticky' => TRUE);
foreach ($role_names as $name) {
$form['permissions']['#header'][] = array('data' => $name, 'class' => array('checkbox'));
}
foreach ($modules as $module => $display_name) {
if ($permissions = $this->moduleHandler->invoke($module, 'permission')) {
// Module name.
$form['permissions'][$module] = array(array('#wrapper_attributes' => array('colspan' => count($role_names) + 1, 'class' => array('module'), 'id' => 'module-' . $module), '#markup' => $module_info[$module]->info['name']));
foreach ($permissions as $perm => $perm_item) {
// Fill in default values for the permission.
$perm_item += array('description' => '', 'restrict access' => FALSE, 'warning' => !empty($perm_item['restrict access']) ? $this->t('Warning: Give to trusted roles only; this permission has security implications.') : '');
$options[$perm] = $perm_item['title'];
// Show the permission description.
if (!$hide_descriptions) {
$user_permission_description = $perm_item['description'];
// Append warning message.
if (!empty($perm_item['warning'])) {
$user_permission_description .= ' <em class="permission-warning">' . $perm_item['warning'] . '</em>';
}
}
$form['permissions'][$perm]['description'] = array('#wrapper_attributes' => array('class' => array('permission')), '#type' => 'item', '#markup' => $perm_item['title'], '#description' => $user_permission_description);
$options[$perm] = '';
foreach ($role_names as $rid => $name) {
$form['permissions'][$perm][$rid] = array('#title' => $name . ': ' . $perm_item['title'], '#title_display' => 'invisible', '#wrapper_attributes' => array('class' => array('checkbox')), '#type' => 'checkbox', '#default_value' => in_array($perm, $role_permissions[$rid]) ? 1 : 0, '#attributes' => array('class' => array('rid-' . $rid)), '#parents' => array($rid, $perm));
}
}
}
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save permissions'));
$form['#attached']['library'][] = 'user/drupal.user.permissions';
return $form;
}
示例9: thirdPartySettingsForm
/**
* {@inheritdoc}
*/
protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, array &$form_state)
{
$settings_form = array();
// Invoke hook_field_formatter_third_party_settings_form(), keying resulting
// subforms by module name.
foreach ($this->moduleHandler->getImplementations('field_formatter_third_party_settings_form') as $module) {
$settings_form[$module] = $this->moduleHandler->invoke($module, 'field_formatter_third_party_settings_form', array($plugin, $field_definition, $this->mode, $form, $form_state));
}
return $settings_form;
}
示例10: build
/**
* {@inheritdoc}
*/
public function build()
{
// Do not show on a 403 or 404 page.
if ($this->request->attributes->has('exception')) {
return [];
}
$implementations = $this->moduleHandler->getImplementations('help');
$build = [];
$args = [$this->routeMatch->getRouteName(), $this->routeMatch];
foreach ($implementations as $module) {
// Don't add empty strings to $build array.
if ($help = $this->moduleHandler->invoke($module, 'help', $args)) {
// Convert strings to #markup render arrays so that they will XSS admin
// filtered.
$build[] = is_array($help) ? $help : ['#markup' => $help];
}
}
return $build;
}
示例11: invokeCronHandlers
/**
* Invokes any cron handlers implementing hook_cron.
*/
protected function invokeCronHandlers()
{
// Iterate through the modules calling their cron handlers (if any):
foreach ($this->moduleHandler->getImplementations('cron') as $module) {
// Do not let an exception thrown by one module disturb another.
try {
$this->moduleHandler->invoke($module, 'cron');
} catch (\Exception $e) {
watchdog_exception('cron', $e);
}
}
}
示例12: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
$this->moduleHandler->getImplementations('entity_type_build')->willReturn([]);
$this->moduleHandler->alter('entity_type', Argument::type('array'))->willReturn(NULL);
$this->cacheBackend = $this->prophesize(CacheBackendInterface::class);
$this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
$this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidatorInterface::class);
$language = new Language(['id' => 'en']);
$this->languageManager = $this->prophesize(LanguageManagerInterface::class);
$this->languageManager->getCurrentLanguage()->willReturn($language);
$this->languageManager->getLanguages()->willReturn(['en' => (object) ['id' => 'en']]);
$this->typedDataManager = $this->prophesize(TypedDataManagerInterface::class);
$this->cacheBackend = $this->prophesize(CacheBackendInterface::class);
$container = $this->prophesize(ContainerInterface::class);
$container->get('cache_tags.invalidator')->willReturn($this->cacheTagsInvalidator->reveal());
//$container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
\Drupal::setContainer($container->reveal());
$this->entityTypeBundleInfo = new EntityTypeBundleInfo($this->entityTypeManager->reveal(), $this->languageManager->reveal(), $this->moduleHandler->reveal(), $this->typedDataManager->reveal(), $this->cacheBackend->reveal());
}
示例13: prepareInvokeAll
/**
* Invokes the specified prepare hook variant.
*
* @param string $hook
* The hook variant name.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
protected function prepareInvokeAll($hook, FormStateInterface $form_state)
{
$implementations = $this->moduleHandler->getImplementations($hook);
foreach ($implementations as $module) {
$function = $module . '_' . $hook;
if (function_exists($function)) {
// Ensure we pass an updated translation object and form display at
// each invocation, since they depend on form state which is alterable.
$args = array($this->entity, $this->operation, &$form_state);
call_user_func_array($function, $args);
}
}
}
示例14: getValueOptions
public function getValueOptions()
{
if (!isset($this->value_options)) {
$module_info = system_get_info('module');
// Get a list of all the modules implementing a hook_permission() and sort by
// display name.
$modules = array();
foreach ($this->moduleHandler->getImplementations('permission') as $module) {
$modules[$module] = $module_info[$module]['name'];
}
asort($modules);
$this->value_options = array();
foreach ($modules as $module => $display_name) {
if ($permissions = $this->moduleHandler->invoke($module, 'permission')) {
foreach ($permissions as $perm => $perm_item) {
$this->value_options[$display_name][$perm] = String::checkPlain(strip_tags($perm_item['title']));
}
}
}
} else {
return $this->value_options;
}
}
示例15: testGetFieldMapByFieldType
/**
* @covers ::getFieldMapByFieldType
*/
public function testGetFieldMapByFieldType()
{
// Set up a content entity type.
$entity_type = $this->prophesize(ContentEntityTypeInterface::class);
$entity_class = EntityManagerTestEntity::class;
// Set up the module handler to return two bundles for the fieldable entity
// type.
$this->moduleHandler->getImplementations('entity_base_field_info')->willReturn([]);
$this->moduleHandler->invokeAll('entity_bundle_info')->willReturn(['test_entity_type' => ['first_bundle' => [], 'second_bundle' => []]]);
$this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL);
// Define an ID field definition as a base field.
$id_definition = $this->prophesize(FieldDefinitionInterface::class);
$id_definition->getType()->willReturn('integer');
$base_field_definitions = array('id' => $id_definition->reveal());
$entity_class::$baseFieldDefinitions = $base_field_definitions;
// Set up the stored bundle field map.
$key_value_store = $this->prophesize(KeyValueStoreInterface::class);
$this->keyValueFactory->get('entity.definitions.bundle_field_map')->willReturn($key_value_store->reveal());
$key_value_store->getAll()->willReturn(['test_entity_type' => ['by_bundle' => ['type' => 'string', 'bundles' => ['second_bundle' => 'second_bundle']]]]);
// Mock the base field definition override.
$override_entity_type = $this->prophesize(EntityTypeInterface::class);
$this->setUpEntityManager(array('test_entity_type' => $entity_type, 'base_field_override' => $override_entity_type));
$entity_type->getClass()->willReturn($entity_class);
$entity_type->getKeys()->willReturn(['default_langcode' => 'default_langcode']);
$entity_type->id()->willReturn('test_entity_type');
$entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE);
$entity_type->getBundleOf()->shouldBeCalled();
$entity_type->isTranslatable()->shouldBeCalled();
$entity_type->getProvider()->shouldBeCalled();
$override_entity_type->getClass()->willReturn($entity_class);
$override_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE);
$override_entity_type->getHandlerClass('storage')->willReturn(TestConfigEntityStorage::class);
$override_entity_type->getBundleOf()->shouldBeCalled();
$override_entity_type->getLabel()->shouldBeCalled();
$integerFields = $this->entityManager->getFieldMapByFieldType('integer');
$this->assertCount(1, $integerFields['test_entity_type']);
$this->assertArrayNotHasKey('non_fieldable', $integerFields);
$this->assertArrayHasKey('id', $integerFields['test_entity_type']);
$this->assertArrayNotHasKey('by_bundle', $integerFields['test_entity_type']);
$stringFields = $this->entityManager->getFieldMapByFieldType('string');
$this->assertCount(1, $stringFields['test_entity_type']);
$this->assertArrayNotHasKey('non_fieldable', $stringFields);
$this->assertArrayHasKey('by_bundle', $stringFields['test_entity_type']);
$this->assertArrayNotHasKey('id', $stringFields['test_entity_type']);
}