Commit 999e819b authored by alexpott's avatar alexpott

Issue #2637304 by legolasbo, Xano: Add missing typehints in EntityAutocomplete

parent 523e4567
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Tags;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\Textfield;
......@@ -146,6 +147,7 @@ public static function validateEntityAutocomplete(array &$element, FormStateInte
'handler' => $element['#selection_handler'],
'handler_settings' => $element['#selection_settings'],
);
/** @var /Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $handler */
$handler = \Drupal::service('plugin.manager.entity_reference_selection')->getInstance($options);
$autocreate = (bool) $element['#autocreate'] && $handler instanceof SelectionWithAutocreateInterface;
......@@ -164,6 +166,7 @@ public static function validateEntityAutocomplete(array &$element, FormStateInte
);
}
elseif ($autocreate) {
/** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface $handler */
// Auto-create item. See an example of how this is handled in
// \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().
$value[] = array(
......@@ -211,6 +214,7 @@ public static function validateEntityAutocomplete(array &$element, FormStateInte
}
foreach ($invalid_new_entities as $entity) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$form_state->setError($element, t('This entity (%type: %label) cannot be referenced.', array('%type' => $element['#target_type'], '%label' => $entity->label())));
}
}
......@@ -233,6 +237,8 @@ public static function validateEntityAutocomplete(array &$element, FormStateInte
* The method will return an entity ID if one single entity unambuguously
* matches the incoming input, and sill assign form errors otherwise.
*
* @param \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $handler
* Entity reference selection plugin.
* @param string $input
* Single string from autocomplete element.
* @param array $element
......@@ -246,7 +252,7 @@ public static function validateEntityAutocomplete(array &$element, FormStateInte
* @return int|null
* Value of a matching entity ID, or NULL if none.
*/
protected static function matchEntityByTitle($handler, $input, &$element, FormStateInterface $form_state, $strict) {
protected static function matchEntityByTitle(SelectionInterface $handler, $input, array &$element, FormStateInterface $form_state, $strict) {
$entities_by_bundle = $handler->getReferenceableEntities($input, '=', 6);
$entities = array_reduce($entities_by_bundle, function ($flattened, $bundle_entities) {
return $flattened + $bundle_entities;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment