本文整理汇总了PHP中Drupal\Core\Extension\ModuleHandlerInterface::moduleExists方法的典型用法代码示例。如果您正苦于以下问题:PHP ModuleHandlerInterface::moduleExists方法的具体用法?PHP ModuleHandlerInterface::moduleExists怎么用?PHP ModuleHandlerInterface::moduleExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Extension\ModuleHandlerInterface
的用法示例。
在下文中一共展示了ModuleHandlerInterface::moduleExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* {@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;
}
示例2: alterRoutes
/**
* {@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);
}
}
}
}
示例3: buildForm
/**
* {@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);
}
示例4: enhance
/**
* {@inheritdoc}
*/
public function enhance(array $defaults, Request $request)
{
if (!$this->moduleHandler->moduleExists('ctools')) {
$defaults['_controller'] = '\\Drupal\\entity_browser\\Controllers\\CtoolsFallback::displayMessage';
}
return $defaults;
}
示例5: tokenBrowser
/**
* 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;
}
示例6: tokenBrowser
/**
* 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();
}
}
示例7:
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');
}
}
示例8: foobarPage
/**
* 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;
}
示例9: submitForm
/**
* {@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);
}
示例10: onRequest
/**
* Initializes devel module requirements.
*/
public function onRequest(GetResponseEvent $event)
{
if (!devel_silent()) {
if ($this->account->hasPermission('access devel information')) {
devel_set_handler(devel_get_handlers());
// We want to include the class early so that anyone may call krumo()
// as needed. See http://krumo.sourceforge.net/
has_krumo();
// See http://www.firephp.org/HQ/Install.htm
$path = NULL;
if (@(include_once 'fb.php') || @(include_once 'FirePHPCore/fb.php')) {
// FirePHPCore is in include_path. Probably a PEAR installation.
$path = '';
} elseif ($this->moduleHandler->moduleExists('libraries')) {
// Support Libraries API - http://drupal.org/project/libraries
$firephp_path = libraries_get_path('FirePHPCore');
$firephp_path = $firephp_path ? $firephp_path . '/lib/FirePHPCore/' : '';
$chromephp_path = libraries_get_path('chromephp');
} else {
$firephp_path = DRUPAL_ROOT . '/libraries/FirePHPCore/lib/FirePHPCore/';
$chromephp_path = './' . drupal_get_path('module', 'devel') . '/chromephp';
}
// Include FirePHP if it exists.
if (!empty($firephp_path) && file_exists($firephp_path . 'fb.php')) {
include_once $firephp_path . 'fb.php';
include_once $firephp_path . 'FirePHP.class.php';
}
// Include ChromePHP if it exists.
if (!empty($chromephp_path) && file_exists($chromephp_path .= '/ChromePhp.php')) {
include_once $chromephp_path;
}
}
}
if ($this->config->get('rebuild_theme')) {
drupal_theme_rebuild();
// Ensure that the active theme object is cleared.
$theme_name = \Drupal::theme()->getActiveTheme()->getName();
\Drupal::state()->delete('theme.active_theme.' . $theme_name);
\Drupal::theme()->resetActiveTheme();
/** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler*/
$theme_handler = \Drupal::service('theme_handler');
$theme_handler->refreshInfo();
// @todo This is not needed after https://www.drupal.org/node/2330755
$list = $theme_handler->listInfo();
$theme_handler->addTheme($list[$theme_name]);
if (\Drupal::service('flood')->isAllowed('devel.rebuild_theme_warning', 1)) {
\Drupal::service('flood')->register('devel.rebuild_theme_warning');
if (!devel_silent() && $this->account->hasPermission('access devel information')) {
drupal_set_message(t('The theme information is being rebuilt on every request. Remember to <a href="@url">turn off</a> this feature on production websites.', array('@url' => $this->urlGenerator->generateFromRoute('devel.admin_settings'))));
}
}
}
drupal_register_shutdown_function('devel_shutdown');
}
示例11: installDependencies
/**
* {@inheritdoc}
*/
public function installDependencies()
{
$modules = ['migrate', 'migrate_drupal'];
foreach ($modules as $i => $module) {
if ($this->moduleHandler->moduleExists($module)) {
unset($modules[$i]);
}
}
if (!empty($modules)) {
$this->moduleInstaller->install($modules, TRUE);
}
return $this;
}
示例12: onRequest
/**
* Initializes devel module requirements.
*/
public function onRequest(GetResponseEvent $event)
{
if (!devel_silent()) {
if ($this->config->get('memory')) {
global $memory_init;
$memory_init = memory_get_usage();
}
if (devel_query_enabled()) {
Database::startLog('devel');
}
if ($this->account->hasPermission('access devel information')) {
devel_set_handler(devel_get_handlers());
// We want to include the class early so that anyone may call krumo()
// as needed. See http://krumo.sourceforge.net/
has_krumo();
// See http://www.firephp.org/HQ/Install.htm
$path = NULL;
if (@(include_once 'fb.php') || @(include_once 'FirePHPCore/fb.php')) {
// FirePHPCore is in include_path. Probably a PEAR installation.
$path = '';
} elseif ($this->moduleHandler->moduleExists('libraries')) {
// Support Libraries API - http://drupal.org/project/libraries
$firephp_path = libraries_get_path('FirePHPCore');
$firephp_path = $firephp_path ? $firephp_path . '/lib/FirePHPCore/' : '';
$chromephp_path = libraries_get_path('chromephp');
} else {
$firephp_path = DRUPAL_ROOT . '/libraries/FirePHPCore/lib/FirePHPCore/';
$chromephp_path = './' . drupal_get_path('module', 'devel') . '/chromephp';
}
// Include FirePHP if it exists.
if (!empty($firephp_path) && file_exists($firephp_path . 'fb.php')) {
include_once $firephp_path . 'fb.php';
include_once $firephp_path . 'FirePHP.class.php';
}
// Include ChromePHP if it exists.
if (!empty($chromephp_path) && file_exists($chromephp_path .= '/ChromePhp.php')) {
include_once $chromephp_path;
}
}
}
if ($this->config->get('rebuild_theme_registry')) {
drupal_theme_rebuild();
if (\Drupal::service('flood')->isAllowed('devel.rebuild_registry_warning', 1)) {
\Drupal::service('flood')->register('devel.rebuild_registry_warning');
if (!devel_silent() && $this->account->hasPermission('access devel information')) {
drupal_set_message(t('The theme registry is being rebuilt on every request. Remember to <a href="!url">turn off</a> this feature on production websites.', array("!url" => url('admin/config/development/devel'))));
}
}
}
drupal_register_shutdown_function('devel_shutdown');
}
示例13: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row['label'] = $this->getLabel($entity);
if ($this->moduleHandler->moduleExists('language')) {
if (isset($entity->context['language'])) {
$language = $this->languageManager->getLanguage($entity->context['language']);
$row['language'] = $language->getName();
} else {
$row['language'] = $this->t('Undefined');
}
}
$row['id'] = $entity->id();
// You probably want a few more properties here...
return $row + parent::buildRow($entity);
}
示例14: getPackageObject
/**
* Initializes and returns a package or profile array.
*
* @param string $machine_name
* Machine name of the package.
* @param string $name
* (optional) Human readable name of the package.
* @param string $description
* (optional) Description of the package.
* @param string $type
* (optional) Type of project.
* @param \Drupal\features\FeaturesBundleInterface $bundle
* (optional) Bundle to use to add profile directories to the scan.
* @param \Drupal\Core\Extension\Extension $extension
* (optional) An Extension object.
*
* @return \Drupal\features\Package
* An array of package properties; see
* FeaturesManagerInterface::getPackages().
*/
protected function getPackageObject($machine_name, $name = NULL, $description = '', $type = 'module', FeaturesBundleInterface $bundle = NULL, Extension $extension = NULL)
{
if (!isset($bundle)) {
$bundle = $this->getAssigner()->getBundle();
}
$package = new Package($machine_name, ['name' => isset($name) ? $name : ucwords(str_replace(['_', '-'], ' ', $machine_name)), 'description' => $description, 'type' => $type, 'core' => Drupal::CORE_COMPATIBILITY, 'dependencies' => [], 'themes' => [], 'config' => [], 'status' => FeaturesManagerInterface::STATUS_DEFAULT, 'version' => '', 'state' => FeaturesManagerInterface::STATE_DEFAULT, 'directory' => $machine_name, 'files' => [], 'bundle' => $bundle->isDefault() ? '' : $bundle->getMachineName(), 'extension' => NULL, 'info' => [], 'configOrig' => []]);
// If no extension was passed in, look for a match.
if (!isset($extension)) {
$module_list = $this->getFeaturesModules($bundle);
$full_name = $bundle->getFullName($package->getMachineName());
if (isset($module_list[$full_name])) {
$extension = $module_list[$full_name];
}
}
// If there is an extension, set extension-specific properties.
if (isset($extension)) {
$info = $this->getExtensionInfo($extension);
$features_info = $this->getFeaturesInfo($extension);
$package->setExtension($extension);
$package->setInfo($info);
$package->setFeaturesInfo($features_info);
$package->setConfigOrig($this->listExtensionConfig($extension));
$package->setStatus($this->moduleHandler->moduleExists($extension->getName()) ? FeaturesManagerInterface::STATUS_INSTALLED : FeaturesManagerInterface::STATUS_UNINSTALLED);
$package->setVersion(isset($info['version']) ? $info['version'] : '');
}
return $package;
}
示例15: getActiveImageStylesMappingPlugins
/**
* Helper function.
*
* Get the image styles mapping plugin which dependencies are enabled.
*/
public function getActiveImageStylesMappingPlugins() {
$active_image_styles_mapping_plugins = array();
// Get the plugins.
$image_styles_mapping_plugins_definitions = $this->imageStylesMappingPluginManager->getDefinitions();
foreach ($image_styles_mapping_plugins_definitions as $plugin_id => $plugin_definition) {
$dependencies = TRUE;
// Instantiate the plugin.
$plugin = $this->imageStylesMappingPluginManager->createInstance($plugin_id, array());
// Check dependencies.
foreach ($plugin->getDependencies() as $module_name) {
if (!$this->moduleHandler->moduleExists($module_name)) {
$dependencies = FALSE;
break;
}
}
// Add the plugin if all dependencies are satisfied.
if ($dependencies) {
$active_image_styles_mapping_plugins[] = $plugin;
}
}
return $active_image_styles_mapping_plugins;
}