public static function BackgroundImageFormTrait::findFirstInput in Background Image 8
Same name and namespace in other branches
- 2.x src/BackgroundImageFormTrait.php \Drupal\background_image\BackgroundImageFormTrait::findFirstInput()
- 2.0.x src/BackgroundImageFormTrait.php \Drupal\background_image\BackgroundImageFormTrait::findFirstInput()
Retrieves first available #input element, going through children if needed.
Parameters
array $element: The render array element to use, passed by reference
bool $file: Flag that indicates whether to use the hidden "fids" field as the input value for managed files.
bool $found: A variable that is passed by reference to determine if the element has been found.
Return value
array The first available #input element, passed by reference.
2 calls to BackgroundImageFormTrait::findFirstInput()
- BackgroundImageForm::buildImage in src/
Form/ BackgroundImageForm.php - Builds the "Image" group.
- BackgroundImageFormTrait::preRenderStates in src/
BackgroundImageFormTrait.php - The #pre_render callback for ::addState.
File
- src/
BackgroundImageFormTrait.php, line 305
Class
- BackgroundImageFormTrait
- Trait BackgroundImageFormTrait.
Namespace
Drupal\background_imageCode
public static function &findFirstInput(array &$element, $file = TRUE, &$found = FALSE) {
// Handle managed files differently (use their hidden fids element).
if (!empty($element['#input']) && isset($element['#type']) && $element['#type'] === 'managed_file' && isset($element['fids']) && $file) {
$fids =& self::findFirstInput($element['fids'], $file, $found);
if ($found && $fids) {
return $fids;
}
return $element;
}
else {
if (!empty($element['#input']) || isset($element['#type']) && $element['#type'] === 'managed_file') {
$found = TRUE;
return $element;
}
}
foreach (Element::children($element) as $child) {
$child_element =& self::findFirstInput($element[$child], $file, $found);
if ($found && $child_element) {
return $child_element;
}
}
return $element;
}