/**
  * {@inheritdoc}
  */
 public function enhance(array $defaults, Request $request)
 {
     if (!$this->moduleHandler->moduleExists('ctools')) {
         $defaults['_controller'] = '\\Drupal\\entity_browser\\Controllers\\CtoolsFallback::displayMessage';
     }
     return $defaults;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function __construct(ModuleHandlerInterface $module_handler)
 {
     $this->alterInfo('rules_event');
     $this->discovery = new ContainerDerivativeDiscoveryDecorator(new YamlDiscovery('rules.events', $module_handler->getModuleDirectories()));
     $this->factory = new ContainerFactory($this, RulesEventInterface::class);
     $this->moduleHandler = $module_handler;
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $link)
 {
     $link += array('access' => 1, 'status' => 1, 'status_override' => 0, 'lastmod' => 0, 'priority' => XMLSITEMAP_PRIORITY_DEFAULT, 'priority_override' => 0, 'changefreq' => 0, 'changecount' => 0, 'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED);
     // Allow other modules to alter the link before saving.
     $this->moduleHandler->alter('xmlsitemap_link', $link);
     // Temporary validation checks.
     // @todo Remove in final?
     if ($link['priority'] < 0 || $link['priority'] > 1) {
         trigger_error(t('Invalid sitemap link priority %priority.<br />@link', array('%priority' => $link['priority'], '@link' => var_export($link, TRUE))), E_USER_ERROR);
     }
     if ($link['changecount'] < 0) {
         trigger_error(t('Negative changecount value. Please report this to <a href="@516928">@516928</a>.<br />@link', array('@516928' => 'http://drupal.org/node/516928', '@link' => var_export($link, TRUE))), E_USER_ERROR);
         $link['changecount'] = 0;
     }
     // Check if this is a changed link and set the regenerate flag if necessary.
     if (!$this->state->get('xmlsitemap_regenerate_needed')) {
         $this->checkChangedLink($link, NULL, TRUE);
     }
     $queryStatus = \Drupal::database()->merge('xmlsitemap')->key(array('type' => $link['type'], 'id' => $link['id']))->fields(array('loc' => $link['loc'], 'subtype' => $link['subtype'], 'access' => $link['access'], 'status' => $link['status'], 'status_override' => $link['status_override'], 'lastmod' => $link['lastmod'], 'priority' => $link['priority'], 'priority_override' => $link['priority_override'], 'changefreq' => $link['changefreq'], 'changecount' => $link['changecount'], 'language' => $link['language']))->execute();
     switch ($queryStatus) {
         case Merge::STATUS_INSERT:
             $this->moduleHandler->invokeAll('xmlsitemap_link_insert', array($link));
             break;
         case Merge::STATUS_UPDATE:
             $this->moduleHandler->invokeAll('xmlsitemap_link_update', array($link));
             break;
     }
     return $link;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     // Create a config mock which does not mock the clear(), set() and get() methods.
     $methods = get_class_methods('Drupal\\Core\\Config\\Config');
     unset($methods[array_search('set', $methods)]);
     unset($methods[array_search('get', $methods)]);
     unset($methods[array_search('clear', $methods)]);
     $config_mock = $this->getMockBuilder('Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->setMethods($methods)->getMock();
     // Create the config factory we use in the submitForm() function.
     $this->configFactory = $this->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
     $this->configFactory->expects($this->any())->method('getEditable')->will($this->returnValue($config_mock));
     // Create a MailsystemManager mock.
     $this->mailManager = $this->getMock('\\Drupal\\mailsystem\\MailsystemManager', array(), array(), '', FALSE);
     $this->mailManager->expects($this->any())->method('getDefinition')->will($this->returnValueMap(array(array('mailsystem_test', TRUE, array('label' => 'Test Mail-Plugin')), array('mailsystem_demo', TRUE, array('label' => 'Demo Mail-Plugin')))));
     $this->mailManager->expects($this->any())->method('getDefinitions')->will($this->returnValue(array(array('id' => 'mailsystem_test', 'label' => 'Test Mail-Plugin'), array('id' => 'mailsystem_demo', 'label' => 'Demo Mail-Plugin'))));
     // Create a module handler mock.
     $this->moduleHandler = $this->getMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->moduleHandler->expects($this->any())->method('getImplementations')->with('mail')->will($this->returnValue(array('mailsystem_test', 'mailsystem_demo')));
     $this->moduleHandler->expects($this->any())->method('moduleExists')->withAnyParameters()->will($this->returnValue(FALSE));
     // Create a theme handler mock.
     $this->themeHandler = $this->getMock('\\Drupal\\Core\\Extension\\ThemeHandlerInterface');
     $this->themeHandler->expects($this->any())->method('listInfo')->will($this->returnValue(array('test_theme' => (object) array('status' => 1, 'info' => array('name' => 'test theme name')), 'demo_theme' => (object) array('status' => 1, 'info' => array('name' => 'test theme name demo')), 'inactive_theme' => (object) array('status' => 0, 'info' => array('name' => 'inactive test theme')))));
     // Inject a language-manager into \Drupal.
     $this->languageManager = $this->getMock('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
     $this->languageManager->expects($this->any())->method('translate')->withAnyParameters()->will($this->returnArgument(0));
     $container = new ContainerBuilder();
     $container->set('string_translation', $this->languageManager);
     \Drupal::setContainer($container);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('xhprof.config');
     $extension_loaded = $this->profiler->isLoaded();
     if ($extension_loaded) {
         $help = $this->t('Profile requests with the XHProf or uprofiler php extension.');
     } else {
         $help = $this->t('You must enable the !xhprof or !uprofiler php extension.', ['!xhprof' => $this->l('XHProf', Url::fromUri('https://www.drupal.org/node/946182')), '!uprofiler' => $this->l('uprofiler', Url::fromUri('https://github.com/FriendsOfPHP/uprofiler'))]);
     }
     $form['help'] = array('#type' => 'inline_template', '#template' => '<span class="warning">{{ help }}</span>', '#context' => array('help' => $help));
     $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable profiling of page views.'), '#default_value' => $extension_loaded & $config->get('enabled'), '#disabled' => !$extension_loaded);
     $form['settings'] = array('#title' => $this->t('Profiling settings'), '#type' => 'details', '#open' => TRUE, '#states' => array('invisible' => array('input[name="enabled"]' => array('checked' => FALSE))));
     $form['settings']['extension'] = array('#type' => 'select', '#title' => $this->t('Extension'), '#options' => $this->profiler->getExtensions(), '#default_value' => $config->get('extension'), '#description' => $this->t('Choose the extension to use for profiling. The recommended extension is !uprofiler because it is actively maintained.', ['!uprofiler' => $this->l('uprofiler', Url::fromUri('https://github.com/FriendsOfPHP/uprofiler'))]));
     $form['settings']['exclude'] = array('#type' => 'textarea', '#title' => $this->t('Exclude'), '#default_value' => $config->get('exclude'), '#description' => $this->t('Path to exclude for profiling. One path per line.'));
     $form['settings']['interval'] = array('#type' => 'number', '#title' => 'Profiling interval', '#min' => 0, '#default_value' => $config->get('interval'), '#description' => $this->t('The approximate number of requests between XHProf samples. Leave zero to profile all requests.'));
     $flags = array('FLAGS_CPU' => $this->t('Cpu'), 'FLAGS_MEMORY' => $this->t('Memory'), 'FLAGS_NO_BUILTINS' => $this->t('Exclude PHP builtin functions'));
     $form['settings']['flags'] = array('#type' => 'checkboxes', '#title' => 'Profile', '#options' => $flags, '#default_value' => $config->get('flags'), '#description' => $this->t('Flags to choose what profile.'));
     $form['settings']['exclude_indirect_functions'] = array('#type' => 'checkbox', '#title' => 'Exclude indirect functions', '#default_value' => $config->get('exclude_indirect_functions'), '#description' => $this->t('Exclude functions like %call_user_func and %call_user_func_array.', array('%call_user_func' => 'call_user_func', '%call_user_func_array' => 'call_user_func_array')));
     $options = $this->storageManager->getStorages();
     $form['settings']['storage'] = array('#type' => 'radios', '#title' => $this->t('Profile storage'), '#default_value' => $config->get('storage'), '#options' => $options, '#description' => $this->t('Choose the storage class.'));
     if ($this->moduleHandler->moduleExists('webprofiler')) {
         $form['webprofiler'] = array('#title' => $this->t('Webprofiler integration'), '#type' => 'details', '#open' => TRUE, '#states' => array('invisible' => array('input[name="enabled"]' => array('checked' => FALSE))));
         $form['webprofiler']['show_summary_toolbar'] = array('#type' => 'checkbox', '#title' => $this->t('Show summary data in toolbar.'), '#default_value' => $config->get('show_summary_toolbar'), '#description' => $this->t('Show data from the overall summary directly into the Webprofiler toolbar. May slow down the toolbar rendering.'));
     }
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($collection as $name => $route) {
         if ($route->hasRequirement('_module_dependencies')) {
             $modules = $route->getRequirement('_module_dependencies');
             $explode_and = $this->explodeString($modules, '+');
             if (count($explode_and) > 1) {
                 foreach ($explode_and as $module) {
                     // If any moduleExists() call returns FALSE, remove the route and
                     // move on to the next.
                     if (!$this->moduleHandler->moduleExists($module)) {
                         $collection->remove($name);
                         continue 2;
                     }
                 }
             } else {
                 // OR condition, exploding on ',' character.
                 foreach ($this->explodeString($modules, ',') as $module) {
                     if ($this->moduleHandler->moduleExists($module)) {
                         continue 2;
                     }
                 }
                 // If no modules are found, and we get this far, remove the route.
                 $collection->remove($name);
             }
         }
     }
 }
Example #7
0
 /**
  * {@inheritdoc}
  *
  * The translation update functions executed here are batch operations which
  * are also used in translation update batches. The batch functions may need
  * to be executed multiple times to complete their task, typically this is the
  * translation import function. When a batch function is not finished, a new
  * queue task is created and added to the end of the queue. The batch context
  * data is needed to continue the batch task is stored in the queue with the
  * queue data.
  */
 public function processItem($data)
 {
     $this->moduleHandler->loadInclude('locale', 'batch.inc');
     list($function, $args) = $data;
     // We execute batch operation functions here to check, download and import
     // the translation files. Batch functions use a context variable as last
     // argument which is passed by reference. When a batch operation is called
     // for the first time a default batch context is created. When called
     // iterative (usually the batch import function) the batch context is passed
     // through via the queue and is part of the $data.
     $last = count($args) - 1;
     if (!is_array($args[$last]) || !isset($args[$last]['finished'])) {
         $batch_context = ['sandbox' => [], 'results' => [], 'finished' => 1, 'message' => ''];
     } else {
         $batch_context = $args[$last];
         unset($args[$last]);
     }
     $args = array_merge($args, [&$batch_context]);
     // Call the batch operation function.
     call_user_func_array($function, $args);
     // If the batch operation is not finished we create a new queue task to
     // continue the task. This is typically the translation import task.
     if ($batch_context['finished'] < 1) {
         unset($batch_context['strings']);
         $this->queue->createItem([$function, $args]);
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $modules = array_filter($form_state['values']['list']);
     $this->moduleHandler->uninstall($modules, FALSE);
     $this->moduleHandler->install($modules, FALSE);
     drupal_set_message(t('Uninstalled and installed: %names.', array('%names' => implode(', ', $modules))));
 }
Example #9
0
 /**
  * @covers ::getOperations
  */
 public function testGetOperations()
 {
     $operation_name = $this->randomMachineName();
     $operations = array($operation_name => array('title' => $this->randomMachineName()));
     $this->moduleHandler->expects($this->once())->method('invokeAll')->with('entity_operation', array($this->role))->will($this->returnValue($operations));
     $this->moduleHandler->expects($this->once())->method('alter')->with('entity_operation');
     $this->container->set('module_handler', $this->moduleHandler);
     $this->role->expects($this->any())->method('access')->will($this->returnValue(AccessResult::allowed()));
     $this->role->expects($this->any())->method('hasLinkTemplate')->will($this->returnValue(TRUE));
     $url = $this->getMockBuilder('\\Drupal\\Core\\Url')->disableOriginalConstructor()->getMock();
     $url->expects($this->any())->method('toArray')->will($this->returnValue(array()));
     $this->role->expects($this->any())->method('urlInfo')->will($this->returnValue($url));
     $list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler);
     $list->setStringTranslation($this->translationManager);
     $operations = $list->getOperations($this->role);
     $this->assertInternalType('array', $operations);
     $this->assertArrayHasKey('edit', $operations);
     $this->assertInternalType('array', $operations['edit']);
     $this->assertArrayHasKey('title', $operations['edit']);
     $this->assertArrayHasKey('delete', $operations);
     $this->assertInternalType('array', $operations['delete']);
     $this->assertArrayHasKey('title', $operations['delete']);
     $this->assertArrayHasKey($operation_name, $operations);
     $this->assertInternalType('array', $operations[$operation_name]);
     $this->assertArrayHasKey('title', $operations[$operation_name]);
 }
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     list($old_visibility, $pages, $roles) = $value;
     $visibility = array();
     // If the block is assigned to specific roles, add the user_role condition.
     if ($roles) {
         $visibility['user_role'] = array('id' => 'user_role', 'roles' => array(), 'context_mapping' => array('user' => '@user.current_user_context:current_user'), 'negate' => FALSE);
         foreach ($roles as $key => $role_id) {
             $roles[$key] = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
         }
         $visibility['user_role']['roles'] = array_combine($roles, $roles);
     }
     if ($pages) {
         // 2 == BLOCK_VISIBILITY_PHP in Drupal 6 and 7.
         if ($old_visibility == 2) {
             // If the PHP module is present, migrate the visibility code unaltered.
             if ($this->moduleHandler->moduleExists('php')) {
                 $visibility['php'] = array('id' => 'php', 'negate' => FALSE, 'php' => $pages);
             } elseif ($this->skipPHP) {
                 throw new MigrateSkipRowException();
             }
         } else {
             $paths = preg_split("(\r\n?|\n)", $pages);
             foreach ($paths as $key => $path) {
                 $paths[$key] = $path === '<front>' ? $path : '/' . ltrim($path, '/');
             }
             $visibility['request_path'] = array('id' => 'request_path', 'negate' => !$old_visibility, 'pages' => implode("\n", $paths));
         }
     }
     return $visibility;
 }
 /**
  * {@inheritdoc}
  */
 public function guess($path)
 {
     if ($this->mapping === NULL) {
         $mapping = $this->defaultMapping;
         // Allow modules to alter the default mapping.
         $this->moduleHandler->alter('file_mimetype_mapping', $mapping);
         $this->mapping = $mapping;
     }
     $extension = '';
     $file_parts = explode('.', drupal_basename($path));
     // Remove the first part: a full filename should not match an extension.
     array_shift($file_parts);
     // Iterate over the file parts, trying to find a match.
     // For my.awesome.image.jpeg, we try:
     //   - jpeg
     //   - image.jpeg, and
     //   - awesome.image.jpeg
     while ($additional_part = array_pop($file_parts)) {
         $extension = strtolower($additional_part . ($extension ? '.' . $extension : ''));
         if (isset($this->mapping['extensions'][$extension])) {
             return $this->mapping['mimetypes'][$this->mapping['extensions'][$extension]];
         }
     }
     return 'application/octet-stream';
 }
Example #12
0
 /**
  * Tests getting the theme registry defined by a module.
  */
 public function testGetRegistryForModule()
 {
     $this->setupTheme('test_theme');
     $this->registry->setTheme(new ActiveTheme(['name' => 'test_theme', 'path' => 'core/modules/system/tests/themes/test_theme/test_theme.info.yml', 'engine' => 'twig', 'owner' => 'twig', 'stylesheets_remove' => [], 'stylesheets_override' => [], 'libraries' => [], 'extension' => '.twig', 'base_themes' => []]));
     // Include the module so that hook_theme can be called.
     include_once $this->root . '/core/modules/system/tests/modules/theme_test/theme_test.module';
     $this->moduleHandler->expects($this->once())->method('getImplementations')->with('theme')->will($this->returnValue(array('theme_test')));
     $registry = $this->registry->get();
     // Ensure that the registry entries from the module are found.
     $this->assertArrayHasKey('theme_test', $registry);
     $this->assertArrayHasKey('theme_test_template_test', $registry);
     $this->assertArrayHasKey('theme_test_template_test_2', $registry);
     $this->assertArrayHasKey('theme_test_suggestion_provided', $registry);
     $this->assertArrayHasKey('theme_test_specific_suggestions', $registry);
     $this->assertArrayHasKey('theme_test_suggestions', $registry);
     $this->assertArrayHasKey('theme_test_function_suggestions', $registry);
     $this->assertArrayHasKey('theme_test_foo', $registry);
     $this->assertArrayHasKey('theme_test_render_element', $registry);
     $this->assertArrayHasKey('theme_test_render_element_children', $registry);
     $this->assertArrayHasKey('theme_test_function_template_override', $registry);
     $this->assertArrayNotHasKey('test_theme_not_existing_function', $registry);
     $info = $registry['theme_test_function_suggestions'];
     $this->assertEquals('module', $info['type']);
     $this->assertEquals('core/modules/system/tests/modules/theme_test', $info['theme path']);
     $this->assertEquals('theme_theme_test_function_suggestions', $info['function']);
     $this->assertEquals(array(), $info['variables']);
 }
 /**
  * Constructs a ConfigMapperManager.
  *
  * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
  *   The cache backend.
  * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
  *   The language manager.
  * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  *   The module handler.
  * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
  *   The typed config manager.
  */
 public function __construct(CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, TypedConfigManagerInterface $typed_config_manager, ThemeHandlerInterface $theme_handler)
 {
     $this->typedConfigManager = $typed_config_manager;
     // Look at all themes and modules.
     // @todo If the list of enabled modules and themes is changed, new
     //   definitions are not picked up immediately and obsolete definitions are
     //   not removed, because the list of search directories is only compiled
     //   once in this constructor. The current code only works due to
     //   coincidence: The request that enables e.g. a new theme does not
     //   instantiate this plugin manager at the beginning of the request; when
     //   routes are being rebuilt at the end of the request, this service only
     //   happens to get instantiated with the updated list of enabled themes.
     $directories = array();
     foreach ($module_handler->getModuleList() as $name => $module) {
         $directories[$name] = $module->getPath();
     }
     foreach ($theme_handler->listInfo() as $theme) {
         $directories[$theme->getName()] = $theme->getPath();
     }
     // Check for files named MODULE.config_translation.yml and
     // THEME.config_translation.yml in module/theme roots.
     $this->discovery = new YamlDiscovery('config_translation', $directories);
     $this->discovery = new InfoHookDecorator($this->discovery, 'config_translation_info');
     $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
     $this->factory = new ContainerFactory($this);
     // Let others alter definitions with hook_config_translation_info_alter().
     $this->moduleHandler = $module_handler;
     $this->themeHandler = $theme_handler;
     $this->alterInfo('config_translation_info');
     // Config translation only uses an info hook discovery, cache by language.
     $cache_key = 'config_translation_info_plugins' . ':' . $language_manager->getCurrentLanguage()->getId();
     $this->setCacheBackend($cache_backend, $cache_key, array('config_translation_info_plugins' => TRUE));
 }
Example #14
0
 /**
  * {@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;
 }
 /**
  * @covers ::getDefinitions
  */
 public function testGetDefinitions()
 {
     $definitions = array('foo' => array('label' => $this->randomMachineName()));
     $this->discovery->expects($this->once())->method('getDefinitions')->willReturn($definitions);
     $this->moduleHandler->expects($this->once())->method('alter')->with('payment_line_item');
     $this->assertSame($definitions, $this->sut->getDefinitions());
 }
Example #16
0
 /**
  * Constructs a TwigEnvironment object and stores cache and storage
  * internally.
  */
 public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler)
 {
     // @todo Pass as arguments from the DIC.
     $this->cache_object = \Drupal::cache();
     // Ensure that twig.engine is loaded, given that it is needed to render a
     // template because functions like twig_drupal_escape_filter are called.
     require_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine';
     // Set twig path namespace for themes and modules.
     $namespaces = array();
     foreach ($module_handler->getModuleList() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($theme_handler->listInfo() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($namespaces as $name => $path) {
         $templatesDirectory = $path . '/templates';
         if (file_exists($templatesDirectory)) {
             $loader->addPath($templatesDirectory, $name);
         }
     }
     $this->templateClasses = array();
     $this->stringLoader = new \Twig_Loader_String();
     parent::__construct($loader, $options);
 }
 /**
  * Gets the human-readable provider label.
  *
  * @param $provider string
  *
  * @return string
  */
 protected function getProviderLabel($provider)
 {
     if ($provider == 'core') {
         return $this->t('Core');
     } else {
         return $this->moduleHandler->getName($provider);
     }
 }
Example #18
0
 /**
  * Gatekeeper function to direct to either the core or contributed Token.
  *
  * @return array
  *   If token module is installed, a popup browser plus a help text. If not
  *   only the help text.
  */
 public function tokenBrowser()
 {
     $form = array();
     $form['intro_text'] = array('#markup' => '<p>' . t('Configure the meta tags below. Use tokens to avoid redundant meta data and search engine penalization. For example, a \'keyword\' value of "example" will be shown on all content using this configuration, whereas using the [node:field_keywords] automatically inserts the "keywords" values from the current entity (node, term, etc).') . '</p>');
     if ($this->moduleHandler->moduleExists('token')) {
         $form['tokens'] = array('#theme' => 'token_tree_link', '#token_types' => 'all', '#global_types' => TRUE, '#click_insert' => TRUE, '#show_restricted' => FALSE, '#recursion_limit' => 3, '#text' => t('Browse available tokens'));
     }
     return $form;
 }
 function __construct(EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler)
 {
     $this->entityManger = $entity_manager;
     $this->moduleHandler = $module_handler;
     if ($this->entityManger && $this->moduleHandler->moduleExists('taxonomy')) {
         $this->termStorage = $this->entityManger->getStorage('taxonomy_term');
         $this->vocabularyStorage = $this->entityManger->getStorage('taxonomy_vocabulary');
     }
 }
Example #20
0
 /**
  * Gatekeeper function to direct to either the core or contributed Token.
  *
  * @return mixed
  */
 public function tokenBrowser()
 {
     // @TODO: Make these optionally return rendered HTML instead of an an array.
     if ($this->moduleHandler->moduleExists('token')) {
         return $this->contribBrowser();
     } else {
         return $this->coreBrowser();
     }
 }
Example #21
0
 /**
  * Returns the help associated with the active menu item.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  */
 protected function getActiveHelp(Request $request)
 {
     // Do not show on a 403 or 404 page.
     if ($request->attributes->has('exception')) {
         return '';
     }
     $help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
     return $help ? implode("\n", $help) : '';
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function getExtensions()
 {
     foreach ($this->moduleHandler->getModuleList() as $module) {
         (yield $this->wrapCoreExtension($module));
     }
     foreach ($this->themeHandler->listInfo() as $theme) {
         (yield $this->wrapCoreExtension($theme));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     $modules = $this->moduleHandler->getModuleList();
     $themes = $this->themeHandler->listInfo();
     $this->data['drupal_extension']['count'] = count($modules) + count($themes);
     $this->data['drupal_extension']['modules'] = $modules;
     $this->data['drupal_extension']['themes'] = $themes;
     $this->data['drupal_extension']['installation_path'] = $this->root . '/';
 }
Example #24
0
 /**
  * An example of a controller method.
  *
  * @return array
  *   A string or render array to be processed by the rendering engine.
  */
 public function foobarPage()
 {
     if ($this->moduleHandler->moduleExists('devel')) {
         $build = array('#markup' => t('This is the developers demo foobar page, yay!'));
     } else {
         $build = array('#markup' => t('This is the demo foobar page.'));
     }
     return $build;
 }
 /**
  * Get an array of country code => country name pairs, altered by alter hooks.
  *
  * @return array
  *   An array of country code => country name pairs.
  *
  * @see \Drupal\Core\Locale\CountryManager::getStandardList()
  */
 public function getList()
 {
     // Populate the country list if it is not already populated.
     if (!isset($this->countries)) {
         $this->countries = static::getStandardList();
         $this->moduleHandler->alter('countries', $this->countries);
     }
     return $this->countries;
 }
Example #26
0
 /**
  * Builds up all element information.
  */
 protected function buildInfo()
 {
     $info = $this->moduleHandler->invokeAll('element_info');
     foreach ($info as $element_type => $element) {
         $info[$element_type]['#type'] = $element_type;
     }
     // Allow modules to alter the element type defaults.
     $this->moduleHandler->alter('element_info', $info);
     return $info;
 }
Example #27
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->config('statistics.settings')->set('count_content_views', $form_state->getValue('statistics_count_content_views'))->save();
     // The popular statistics block is dependent on these settings, so clear the
     // block plugin definitions cache.
     if ($this->moduleHandler->moduleExists('block')) {
         \Drupal::service('plugin.manager.block')->clearCachedDefinitions();
     }
     parent::submitForm($form, $form_state);
 }
Example #28
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $modules = $this->moduleHandler->getModuleList();
     $names = array();
     foreach (array_keys($modules) as $name) {
         $names[$name] = $this->moduleHandler->getName($name);
     }
     $form['data_module'] = array('#title' => $this->t('Module name'), '#type' => 'select', '#description' => $this->t('The module which sets this user data.'), '#default_value' => $this->options['data_module'], '#options' => $names);
     $form['data_name'] = array('#title' => $this->t('Name'), '#type' => 'textfield', '#description' => $this->t('The name of the data key.'), '#default_value' => $this->options['data_name']);
 }
 /**
  * {@inheritdoc}
  */
 protected function getDiscovery()
 {
     if (!isset($this->discovery)) {
         $directories = array_map(function ($directory) {
             return [$directory . '/migration_templates', $directory . '/migrations'];
         }, $this->moduleHandler->getModuleDirectories());
         $yaml_discovery = new YamlDirectoryDiscovery($directories, 'migrate');
         $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
     }
     return $this->discovery;
 }
Example #30
0
 /**
  * {@inheritdoc}
  */
 public function getEntityTypeMappings()
 {
     if (empty($this->entityMappings)) {
         foreach ($this->entityTypeManager->getDefinitions() as $entity_type => $info) {
             $this->entityMappings[$entity_type] = $info->get('token_type') ?: $entity_type;
         }
         // Allow modules to alter the mapping array.
         $this->moduleHandler->alter('token_entity_mapping', $this->entityMappings);
     }
     return $this->entityMappings;
 }