contrib modules updates
This commit is contained in:
@@ -28,8 +28,6 @@ class Matcher extends Plugin {
|
||||
/**
|
||||
* The human-readable name of the matcher.
|
||||
*
|
||||
* The string should be wrapped in a @Translation().
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*/
|
||||
public $label;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\linkit\Controller;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\linkit\SuggestionManager;
|
||||
@@ -77,7 +76,7 @@ class AutocompleteController implements ContainerInjectionInterface {
|
||||
$this->linkitProfile = $this->linkitProfileStorage->load($linkit_profile_id);
|
||||
$string = $request->query->get('q');
|
||||
|
||||
$suggestionCollection = $this->suggestionManager->getSuggestions($this->linkitProfile, Unicode::strtolower($string));
|
||||
$suggestionCollection = $this->suggestionManager->getSuggestions($this->linkitProfile, mb_strtolower($string));
|
||||
|
||||
/*
|
||||
* If there are no suggestions from the matcher plugins, we have to add a
|
||||
|
||||
@@ -26,6 +26,7 @@ class Linkit extends FormElement {
|
||||
'#process' => [
|
||||
[$class, 'processLinkitAutocomplete'],
|
||||
[$class, 'processGroup'],
|
||||
[$class, 'processAjaxForm'],
|
||||
],
|
||||
'#pre_render' => [
|
||||
[$class, 'preRenderLinkitElement'],
|
||||
|
||||
@@ -120,7 +120,7 @@ class AddForm extends FormBase {
|
||||
]);
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('Added %label matcher.', ['%label' => $plugin->getLabel()]));
|
||||
$this->messenger()->addMessage($this->t('Added %label matcher.', ['%label' => $plugin->getLabel()]));
|
||||
|
||||
$form_state->setRedirect('linkit.matchers', [
|
||||
'linkit_profile' => $this->linkitProfile->id(),
|
||||
|
||||
@@ -70,7 +70,7 @@ class DeleteForm extends ConfirmFormBase {
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->linkitProfile->removeMatcher($this->linkitMatcher);
|
||||
|
||||
drupal_set_message($this->t('The matcher %label has been deleted.', ['%label' => $this->linkitMatcher->getLabel()]));
|
||||
$this->messenger()->addMessage($this->t('The matcher %label has been deleted.', ['%label' => $this->linkitMatcher->getLabel()]));
|
||||
$this->logger('linkit')->notice('The matcher %label has been deleted in the @profile profile.', [
|
||||
'%label' => $this->linkitMatcher->getLabel(),
|
||||
'@profile' => $this->linkitProfile->label(),
|
||||
|
||||
@@ -74,7 +74,7 @@ class EditForm extends FormBase {
|
||||
$this->linkitMatcher->submitConfigurationForm($form, $plugin_data);
|
||||
$this->linkitProfile->save();
|
||||
|
||||
drupal_set_message($this->t('Saved %label configuration.', ['%label' => $this->linkitMatcher->getLabel()]));
|
||||
$this->messenger()->addMessage($this->t('Saved %label configuration.', ['%label' => $this->linkitMatcher->getLabel()]));
|
||||
$this->logger('linkit')->notice('The matcher %label has been updated in the @profile profile.', [
|
||||
'%label' => $this->linkitMatcher->getLabel(),
|
||||
'@profile' => $this->linkitProfile->label(),
|
||||
|
||||
@@ -7,7 +7,7 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
/**
|
||||
* Controller for profile addition forms.
|
||||
*
|
||||
* @see \Drupal\linkit\Profile\FormBase
|
||||
* @see \Drupal\linkit\Form\Profile\FormBase
|
||||
*/
|
||||
class AddForm extends FormBase {
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
/**
|
||||
* Provides an edit form for profile.
|
||||
*
|
||||
* @see \Drupal\linkit\Profile\FormBase
|
||||
* @see \Drupal\linkit\Form\Profile\FormBase
|
||||
*/
|
||||
class EditForm extends FormBase {
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ abstract class FormBase extends EntityForm {
|
||||
$edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString();
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created new profile %label.', ['%label' => $linkit_profile->label()]));
|
||||
$this->messenger()->addMessage($this->t('Created new profile %label.', ['%label' => $linkit_profile->label()]));
|
||||
$this->logger('linkit')->notice('Created new profile %label.', ['%label' => $linkit_profile->label(), 'link' => $edit_link]);
|
||||
$form_state->setRedirect('linkit.matchers', [
|
||||
'linkit_profile' => $linkit_profile->id(),
|
||||
@@ -75,7 +75,7 @@ abstract class FormBase extends EntityForm {
|
||||
break;
|
||||
|
||||
case SAVED_UPDATED:
|
||||
drupal_set_message($this->t('Updated profile %label.', ['%label' => $linkit_profile->label()]));
|
||||
$this->messenger()->addMessage($this->t('Updated profile %label.', ['%label' => $linkit_profile->label()]));
|
||||
$this->logger('linkit')->notice('Updated profile %label.', ['%label' => $linkit_profile->label(), 'link' => $edit_link]);
|
||||
$form_state->setRedirectUrl($linkit_profile->toUrl('edit-form'));
|
||||
break;
|
||||
|
||||
@@ -36,6 +36,11 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
||||
|
||||
use MatcherTokensTrait;
|
||||
|
||||
/**
|
||||
* The default limit for matches.
|
||||
*/
|
||||
const DEFAULT_LIMIT = 100;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
@@ -161,6 +166,12 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
||||
$summery[] = $this->t('Group by bundle: @bundle_grouping', [
|
||||
'@bundle_grouping' => $this->configuration['group_by_bundle'] ? $this->t('Yes') : $this->t('No'),
|
||||
]);
|
||||
|
||||
if (!empty($this->configuration['limit'])) {
|
||||
$summery[] = $this->t('Limit: @limit', [
|
||||
'@limit' => $this->configuration['limit'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $summery;
|
||||
@@ -175,6 +186,7 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
||||
'bundles' => [],
|
||||
'group_by_bundle' => FALSE,
|
||||
'substitution_type' => SubstitutionManagerInterface::DEFAULT_SUBSTITUTION,
|
||||
'limit' => static::DEFAULT_LIMIT,
|
||||
] + parent::defaultConfiguration();
|
||||
}
|
||||
|
||||
@@ -257,6 +269,25 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
||||
'#description' => $this->t('Configure how the selected entity should be transformed into a URL for insertion.'),
|
||||
];
|
||||
|
||||
$form['limit'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Limit'),
|
||||
'#open' => TRUE,
|
||||
];
|
||||
|
||||
$form['limit']['limit'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => [
|
||||
0 => $this->t('Unlimited'),
|
||||
20 => 20,
|
||||
50 => 50,
|
||||
100 => 100,
|
||||
200 => 200,
|
||||
],
|
||||
'#title' => $this->t('Limit search results'),
|
||||
'#description' => $this->t('Limit the amount of results displayed when searching.'),
|
||||
'#default_value' => $this->configuration['limit'],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -274,6 +305,7 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
||||
$this->configuration['bundles'] = $form_state->getValue('bundles');
|
||||
$this->configuration['group_by_bundle'] = $form_state->getValue('group_by_bundle');
|
||||
$this->configuration['substitution_type'] = $form_state->getValue('substitution_type');
|
||||
$this->configuration['limit'] = $form_state->getValue('limit');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,6 +385,9 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
||||
$query->condition($bundle_key, $this->configuration['bundles'], 'IN');
|
||||
}
|
||||
|
||||
if ($this->configuration['limit']) {
|
||||
$query->range(0, $this->configuration['limit']);
|
||||
}
|
||||
$this->addQueryTags($query);
|
||||
|
||||
return $query;
|
||||
|
||||
@@ -190,22 +190,30 @@ class FileMatcher extends EntityMatcher {
|
||||
/** @var \Drupal\file\FileInterface $entity */
|
||||
$file = $entity->getFileUri();
|
||||
|
||||
/** @var \Drupal\Core\Image\ImageInterface $image */
|
||||
$image = \Drupal::service('image.factory')->get($file);
|
||||
if ($image->isValid()) {
|
||||
if ($this->configuration['images']['show_dimensions']) {
|
||||
$description_array[] = $image->getWidth() . 'x' . $image->getHeight() . 'px';
|
||||
}
|
||||
if ($this->configuration['images']['show_dimensions'] || $this->configuration['images']['show_thumbnail']) {
|
||||
$image_factory = \Drupal::service('image.factory');
|
||||
$supported_extensions = $image_factory->getSupportedExtensions();
|
||||
|
||||
if ($this->configuration['images']['show_thumbnail'] && $this->moduleHandler->moduleExists('image')) {
|
||||
$image_element = [
|
||||
'#weight' => -10,
|
||||
'#theme' => 'image_style',
|
||||
'#style_name' => $this->configuration['images']['thumbnail_image_style'],
|
||||
'#uri' => $entity->getFileUri(),
|
||||
];
|
||||
// Check if the file extension is supported by the image toolkit.
|
||||
if (empty(file_validate_extensions($entity, implode(' ', $supported_extensions)))) {
|
||||
/** @var \Drupal\Core\Image\ImageInterface $image */
|
||||
$image = $image_factory->get($file);
|
||||
if ($image->isValid()) {
|
||||
if ($this->configuration['images']['show_dimensions']) {
|
||||
$description_array[] = $image->getWidth() . 'x' . $image->getHeight() . 'px';
|
||||
}
|
||||
|
||||
$description_array[] = (string) \Drupal::service('renderer')->render($image_element);
|
||||
if ($this->configuration['images']['show_thumbnail'] && $this->moduleHandler->moduleExists('image')) {
|
||||
$image_element = [
|
||||
'#weight' => -10,
|
||||
'#theme' => 'image_style',
|
||||
'#style_name' => $this->configuration['images']['thumbnail_image_style'],
|
||||
'#uri' => $entity->getFileUri(),
|
||||
];
|
||||
|
||||
$description_array[] = (string) \Drupal::service('renderer')->render($image_element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\linkit\Plugin\Linkit\Matcher;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
* Provides specific linkit matchers for the node entity type.
|
||||
@@ -84,9 +85,27 @@ class NodeMatcher extends EntityMatcher {
|
||||
protected function buildEntityQuery($search_string) {
|
||||
$query = parent::buildEntityQuery($search_string);
|
||||
|
||||
$no_access = !$this->currentUser->hasPermission('bypass node access') && !count($this->moduleHandler->getImplementations('node_grants'));
|
||||
if ($this->configuration['include_unpublished'] !== TRUE || $no_access) {
|
||||
$query->condition('status', NODE_PUBLISHED);
|
||||
if ($this->configuration['include_unpublished'] == FALSE) {
|
||||
$query->condition('status', NodeInterface::PUBLISHED);
|
||||
}
|
||||
elseif (count($this->moduleHandler->getImplementations('node_grants')) === 0) {
|
||||
if (($this->currentUser->hasPermission('bypass node access') || $this->currentUser->hasPermission('view any unpublished content'))) {
|
||||
// User can see all content, no check necessary.
|
||||
}
|
||||
elseif ($this->currentUser->hasPermission('view own unpublished content')) {
|
||||
// Users with "view own unpublished content" can see only their own.
|
||||
if ($this->configuration['include_unpublished'] == TRUE) {
|
||||
$or_condition = $query
|
||||
->orConditionGroup()
|
||||
->condition('status', NodeInterface::PUBLISHED)
|
||||
->condition('uid', $this->currentUser->id());
|
||||
$query->condition($or_condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// All other users should only get published results.
|
||||
$query->condition('status', NodeInterface::PUBLISHED);
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace Drupal\linkit\Plugin\Linkit\Substitution;
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManager;
|
||||
use Drupal\Core\GeneratedUrl;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\linkit\SubstitutionInterface;
|
||||
@@ -21,30 +20,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
*/
|
||||
class Media extends PluginBase implements SubstitutionInterface, ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManager
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Constructs a Media object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManager $entity_type_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\linkit\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\linkit\Entity\Profile;
|
||||
|
||||
/**
|
||||
@@ -29,7 +28,7 @@ trait ProfileCreationTrait {
|
||||
protected function createProfile(array $settings = []) {
|
||||
// Populate defaults array.
|
||||
$settings += [
|
||||
'id' => Unicode::strtolower($this->randomMachineName()),
|
||||
'id' => mb_strtolower($this->randomMachineName()),
|
||||
'label' => $this->randomMachineName(),
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user