本文整理汇总了PHP中Drupal\Core\Extension\ModuleHandlerInterface::alter方法的典型用法代码示例。如果您正苦于以下问题:PHP ModuleHandlerInterface::alter方法的具体用法?PHP ModuleHandlerInterface::alter怎么用?PHP ModuleHandlerInterface::alter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Extension\ModuleHandlerInterface
的用法示例。
在下文中一共展示了ModuleHandlerInterface::alter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* {@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;
}
示例2: guess
/**
* {@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';
}
示例3: getList
/**
* 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;
}
示例4: buildInfo
/**
* 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;
}
示例5: getEnabledList
/**
* {@inheritdoc}
*/
public function getEnabledList()
{
$countries = $this->entityTypeManager->getStorage('uc_country')->loadByProperties(['status' => TRUE]);
$country_names = [];
foreach ($countries as $alpha_2 => $country) {
$country_names[$alpha_2] = t($country->getName());
}
natcasesort($country_names);
$this->moduleHandler->alter('countries', $country_names);
return $country_names;
}
示例6: getEntityTypeMappings
/**
* {@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;
}
示例7: 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());
}
示例8: getLibrariesByExtension
/**
* {@inheritdoc}
*/
public function getLibrariesByExtension($extension)
{
if (!isset($this->libraryDefinitions[$extension])) {
$libraries = $this->collector->get($extension);
$this->libraryDefinitions[$extension] = [];
foreach ($libraries as $name => $definition) {
// Allow modules and themes to dynamically attach request and context
// specific data for this library; e.g., localization.
$library_name = "{$extension}/{$name}";
$this->moduleHandler->alter('library', $definition, $library_name);
$this->libraryDefinitions[$extension][$name] = $definition;
}
}
return $this->libraryDefinitions[$extension];
}
示例9: getAllBundleInfo
/**
* {@inheritdoc}
*/
public function getAllBundleInfo()
{
if (empty($this->bundleInfo)) {
$langcode = $this->languageManager->getCurrentLanguage()->getId();
if ($cache = $this->cacheGet("entity_bundle_info:{$langcode}")) {
$this->bundleInfo = $cache->data;
} else {
$this->bundleInfo = $this->moduleHandler->invokeAll('entity_bundle_info');
foreach ($this->entityTypeManager->getDefinitions() as $type => $entity_type) {
// First look for entity types that act as bundles for others, load them
// and add them as bundles.
if ($bundle_entity_type = $entity_type->getBundleEntityType()) {
foreach ($this->entityTypeManager->getStorage($bundle_entity_type)->loadMultiple() as $entity) {
$this->bundleInfo[$type][$entity->id()]['label'] = $entity->label();
}
} elseif (!isset($this->bundleInfo[$type])) {
$this->bundleInfo[$type][$type]['label'] = $entity_type->getLabel();
}
}
$this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo);
$this->cacheSet("entity_bundle_info:{$langcode}", $this->bundleInfo, Cache::PERMANENT, ['entity_types', 'entity_bundles']);
}
}
return $this->bundleInfo;
}
示例10: register
/**
* Registers the tagged stream wrappers.
*
* Internal use only.
*/
public function register()
{
$this->moduleHandler->alter('stream_wrappers', $this->info);
foreach ($this->info as $scheme => $info) {
$this->registerWrapper($scheme, $info['class'], $info['type']);
}
}
示例11: build
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match)
{
$breadcrumb = array();
$context = array('builder' => NULL);
// Call the build method of registered breadcrumb builders,
// until one of them returns an array.
foreach ($this->getSortedBuilders() as $builder) {
if (!$builder->applies($route_match)) {
// The builder does not apply, so we continue with the other builders.
continue;
}
$build = $builder->build($route_match);
if (is_array($build)) {
// The builder returned an array of breadcrumb links.
$breadcrumb = $build;
$context['builder'] = $builder;
break;
} else {
throw new \UnexpectedValueException(SafeMarkup::format('Invalid breadcrumb returned by !class::build().', array('!class' => get_class($builder))));
}
}
// Allow modules to alter the breadcrumb.
$this->moduleHandler->alter('system_breadcrumb', $breadcrumb, $route_match, $context);
// Fall back to an empty breadcrumb.
return $breadcrumb;
}
示例12: processQueues
/**
* Processes cron queues.
*/
protected function processQueues()
{
// Grab the defined cron queues.
$queues = $this->moduleHandler->invokeAll('queue_info');
$this->moduleHandler->alter('queue_info', $queues);
foreach ($queues as $queue_name => $info) {
if (isset($info['cron'])) {
// Make sure every queue exists. There is no harm in trying to recreate
// an existing queue.
$this->queueFactory->get($queue_name)->createQueue();
$callback = $info['worker callback'];
$end = time() + (isset($info['cron']['time']) ? $info['cron']['time'] : 15);
$queue = $this->queueFactory->get($queue_name);
while (time() < $end && ($item = $queue->claimItem())) {
try {
call_user_func_array($callback, array($item->data));
$queue->deleteItem($item);
} catch (SuspendQueueException $e) {
// If the worker indicates there is a problem with the whole queue,
// release the item and skip to the next queue.
$queue->releaseItem($item);
watchdog_exception('cron', $e);
// Skip to the next queue.
continue 2;
} catch (\Exception $e) {
// In case of any other kind of exception, log it and leave the item
// in the queue to be processed again later.
watchdog_exception('cron', $e);
}
}
}
}
}
示例13: testGetAllBundleInfo
/**
* Tests the getAllBundleInfo() method.
*
* @covers ::getAllBundleInfo
*/
public function testGetAllBundleInfo()
{
$this->moduleHandler->invokeAll('entity_bundle_info')->willReturn([]);
$this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL);
$apple = $this->prophesize(EntityTypeInterface::class);
$apple->getLabel()->willReturn('Apple');
$apple->getBundleOf()->willReturn(NULL);
$banana = $this->prophesize(EntityTypeInterface::class);
$banana->getLabel()->willReturn('Banana');
$banana->getBundleOf()->willReturn(NULL);
$this->setUpEntityTypeDefinitions(['apple' => $apple, 'banana' => $banana]);
$this->cacheBackend->get('entity_bundle_info:en')->willReturn(FALSE);
$this->cacheBackend->set('entity_bundle_info:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_bundles'])->will(function () {
$this->get('entity_bundle_info:en')->willReturn((object) ['data' => 'cached data'])->shouldBeCalled();
})->shouldBeCalled();
$this->cacheTagsInvalidator->invalidateTags(['entity_bundles'])->shouldBeCalled();
$this->typedDataManager->clearCachedDefinitions()->shouldBeCalled();
$expected = ['apple' => ['apple' => ['label' => 'Apple']], 'banana' => ['banana' => ['label' => 'Banana']]];
$bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
$this->assertSame($expected, $bundle_info);
$bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
$this->assertSame($expected, $bundle_info);
$this->entityTypeBundleInfo->clearCachedBundles();
$bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
$this->assertSame('cached data', $bundle_info);
}
示例14: ssoUserData
/**
* Assembles user-specific data used by Disqus SSO.
*
* @return array
*/
protected function ssoUserData()
{
$account = $this->currentUser;
$data = [];
if (!$account->isAnonymous()) {
$data['id'] = $account->id();
$data['username'] = $account->getAccountName();
$data['email'] = $account->getEmail();
$data['url'] = Url::fromRoute('entity.user.canonical', ['user' => $account->id()], ['absolute' => TRUE])->toString();
// Load the user's avatar.
$user_picture_default = \Drupal::config('field.instance.user.user.user_picture')->get('settings.default_image');
$user = user_load($account->id());
if (isset($user->user_picture->target_id) && !empty($user->user_picture->target_id) && ($file = file_load($user->user_picture->target_id))) {
$file_uri = $file->getFileUri();
$data['avatar'] = !empty($file_uri) ? $file_uri : NULL;
} elseif (!empty($user_picture_default['fid']) && ($file = file_load($user_picture_default['fid']))) {
$file_uri = $file->getFileUri();
$data['avatar'] = !empty($file_uri) ? $file_uri : NULL;
}
if (isset($data['avatar'])) {
$data['avatar'] = file_create_url($data['avatar']);
}
}
$this->moduleHandler->alter('disqus_user_data', $data);
return $data;
}
示例15: entityForm
/**
* {@inheritdoc}
*/
public function entityForm($entity_form, FormStateInterface $form_state) {
$operation = 'default';
$controller = $this->entityTypeManager->getFormObject($entity_form['#entity']->getEntityTypeId(), $operation, FALSE);
$controller->setEntity($entity_form['#entity']);
$form_state->set(['inline_entity_form', $entity_form['#ief_id'], 'entity_form'], $controller);
$child_form_state = $this->buildChildFormState($controller, $form_state, $entity_form['#entity'], $operation, $entity_form['#parents']);
$entity_form = $controller->buildForm($entity_form, $child_form_state);
if (!$entity_form['#display_actions']) {
unset($entity_form['actions']);
}
// TODO - this is field-only part of the code. Figure out how to refactor.
if ($child_form_state->get('inline_entity_form')) {
foreach ($child_form_state->get('inline_entity_form') as $id => $data) {
$form_state->set(['inline_entity_form', $id], $data);
}
}
$form_state->set('field', $child_form_state->get('field'));
$entity_form['#element_validate'][] = [get_class($this), 'entityFormValidate'];
$entity_form['#ief_element_submit'][] = [get_class($this), 'entityFormSubmit'];
$entity_form['#ief_element_submit'][] = [get_class($this), 'submitCleanFormState'];
// Allow other modules to alter the form.
$this->moduleHandler->alter('inline_entity_form_entity_form', $entity_form, $form_state);
return $entity_form;
}