当前位置: 首页>>代码示例>>PHP>>正文


PHP ModuleHandlerInterface::implementsHook方法代码示例

本文整理汇总了PHP中Drupal\Core\Extension\ModuleHandlerInterface::implementsHook方法的典型用法代码示例。如果您正苦于以下问题:PHP ModuleHandlerInterface::implementsHook方法的具体用法?PHP ModuleHandlerInterface::implementsHook怎么用?PHP ModuleHandlerInterface::implementsHook使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Extension\ModuleHandlerInterface的用法示例。


在下文中一共展示了ModuleHandlerInterface::implementsHook方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
 }
开发者ID:ddrozdik,项目名称:DrupalConsole,代码行数:33,代码来源:ExecuteCommand.php

示例2: testHooks

 /**
  * Tests the hooks.
  */
 public function testHooks()
 {
     $view = Views::getView('test_view');
     $view->setDisplay();
     // Test each hook is found in the implementations array and is invoked.
     foreach (static::$hooks as $hook => $type) {
         $this->assertTrue($this->moduleHandler->implementsHook('views_test_data', $hook), format_string('The hook @hook was registered.', array('@hook' => $hook)));
         if ($hook == 'views_post_render') {
             $this->moduleHandler->invoke('views_test_data', $hook, array($view, &$view->display_handler->output, $view->display_handler->getPlugin('cache')));
             continue;
         }
         switch ($type) {
             case 'view':
                 $this->moduleHandler->invoke('views_test_data', $hook, array($view));
                 break;
             case 'alter':
                 $data = array();
                 $this->moduleHandler->invoke('views_test_data', $hook, array($data));
                 break;
             default:
                 $this->moduleHandler->invoke('views_test_data', $hook);
         }
         $this->assertTrue($this->container->get('state')->get('views_hook_test_' . $hook), format_string('The %hook hook was invoked.', array('%hook' => $hook)));
         // Reset the module implementations cache, so we ensure that the
         // .views.inc file is loaded actively.
         $this->moduleHandler->resetImplementations();
     }
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:31,代码来源:ViewsHooksTest.php

示例3: parseLibraryInfo

 /**
  * Parses a given library file and allows module to alter it.
  *
  * This method sets the parsed information onto the library property.
  *
  * @param string $extension
  *   The name of the extension that registered a library.
  * @param string $path
  *   The relative path to the extension.
  *
  * @return array
  *   An array of parsed library data.
  *
  * @throws \Drupal\Core\Asset\Exception\InvalidLibraryFileException
  *   Thrown when a parser exception got thrown.
  */
 protected function parseLibraryInfo($extension, $path)
 {
     $libraries = [];
     $library_file = $path . '/' . $extension . '.libraries.yml';
     if (file_exists($this->root . '/' . $library_file)) {
         try {
             $libraries = Yaml::decode(file_get_contents($this->root . '/' . $library_file));
         } catch (InvalidDataTypeException $e) {
             // Rethrow a more helpful exception to provide context.
             throw new InvalidLibraryFileException(sprintf('Invalid library definition in %s: %s', $library_file, $e->getMessage()), 0, $e);
         }
     }
     // Allow modules to add dynamic library definitions.
     $hook = 'library_info_build';
     if ($this->moduleHandler->implementsHook($extension, $hook)) {
         $libraries = NestedArray::mergeDeep($libraries, $this->moduleHandler->invoke($extension, $hook));
     }
     // Allow modules to alter the module's registered libraries.
     $this->moduleHandler->alter('library_info', $libraries, $extension);
     return $libraries;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:37,代码来源:LibraryDiscoveryParser.php


注:本文中的Drupal\Core\Extension\ModuleHandlerInterface::implementsHook方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。