1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 01:34:31 +02:00

A couple of new convenience methods added to InputfieldWrapper

This commit is contained in:
Ryan Cramer
2021-02-05 10:36:03 -05:00
parent 80593fb643
commit 4ea5d7a631

View File

@@ -1255,6 +1255,8 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
/**
* Given an Inputfield name, return the child Inputfield or NULL if not found.
*
* This traverses all children recursively to find the requested Inputfield.
*
* This is the same as the `InputfieldWrapper::get()` method except that it can
* only return Inputfield or null, and has no crossover with other settings,
* properties or API variables.
@@ -1280,6 +1282,37 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
return $inputfield;
}
/**
* Shorter alias of getChildByName()
*
* #pw-group-retrieval-and-traversal
*
* @param string $name
* @return Inputfield|null
* @since 3.0.172
*
*/
public function getByName($name) {
return $this->getChildByName($name);
}
/**
* Get value of Inputfield by name
*
* This traverses all children recursively to find the requested Inputfield,
* and get the value attribute from it. A value of null is returned if the
* Inputfield cannot be found.
*
* @param string $name
* @return string|int|float|bool|array|object|null
* @since 3.0.172
*
*/
public function getValueByName($name) {
$inputfield = $this->getChildByName($name);
return $inputfield ? $inputfield->val() : null;
}
/**
* Enables foreach() of the children of this class
*