Skip to content

Commit

Permalink
UI: add Input\Container::withInputData for awesome flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
klees committed Dec 19, 2024
1 parent 8e3351a commit 9b87723
Show file tree
Hide file tree
Showing 42 changed files with 92 additions and 54 deletions.
13 changes: 13 additions & 0 deletions components/ILIAS/UI/src/Component/Input/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use ILIAS\Refinery\Transformation;
use Psr\Http\Message\ServerRequestInterface;
use ILIAS\UI\Component\Input\Input;
use ILIAS\UI\Component\Input\InputData;

/**
* This describes commonalities between all Containers for Inputs, such as Forms.
Expand All @@ -40,10 +41,22 @@ public function getInputs(): array;
/**
* Get a form like this where data from the request is attached.
*
* This calls `withInputData` with a properly wrapped request.
*
* @return static
*/
public function withRequest(ServerRequestInterface $request): self;

/**
* Get a form like this where some input data is attached.
*
* This is a more powerful version of `withRequest` that allows to provide
* data from arbitrary to the form. This is one piece that turns the inputs
* from the UI framework into a truly generic input description that can be
* used in various contexts.
*/
public function withInput(InputData $input_data): self;

/**
* Apply a transformation to the data of the form.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

declare(strict_types=1);

namespace ILIAS\UI\Implementation\Component\Input;
namespace ILIAS\UI\Component\Input;

use LogicException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Psr\Http\Message\ServerRequestInterface;
use ILIAS\UI\Component\ReplaceSignal;
use ILIAS\UI\Component\Input\Container\Form\FormInput;
use ILIAS\UI\Component\Input\InputData;

/**
* @author Thibeau Fuhrer <[email protected]>
Expand Down Expand Up @@ -218,6 +219,13 @@ public function withRequest(ServerRequestInterface $request): self
return $clone;
}

public function withInput(InputData $input_data): self
{
$clone = clone $this;
$clone->modal = $clone->modal->withInput($request);
return $clone;
}

public function withAdditionalTransformation(Transformation $trafo): self
{
$clone = clone $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace ILIAS\UI\Implementation\Component\Input;

use LogicException;
use ILIAS\UI\Component\Input\InputData;

/**
* @author Thibeau Fuhrer <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use ILIAS\UI\Component as C;
use ILIAS\UI\Implementation\Component as CI;
use ILIAS\UI\Implementation\Component\Input\NameSource;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\Refinery\Transformation;
use Psr\Http\Message\ServerRequestInterface;
use ILIAS\Data\Result;
Expand Down Expand Up @@ -63,10 +63,15 @@ public function getInputs(): array
*/
public function withRequest(ServerRequestInterface $request): self
{
$post_data = $this->extractRequestData($request);
return $this->withInput(
$this->extractRequestData($request)
);
}

public function withInput(InputData $input_data): self
{
$clone = clone $this;
$clone->input_group = $this->getInputGroup()->withInput($post_data);
$clone->input_group = $this->getInputGroup()->withInput($input_data);
$clone->result = $clone->input_group->getContent();

if (!$clone->result->isok()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ILIAS\UI\Implementation\Component\JavaScriptBindable;
use Psr\Http\Message\ServerRequestInterface;
use ILIAS\UI\Implementation\Component\Input\QueryParamsFromServerRequest;
use ILIAS\UI\Component\Input\InputData;

/**
* This implements commonalities between all Filters.
Expand Down Expand Up @@ -243,7 +244,7 @@ public function getData()
/**
* Extract post data from request.
*/
protected function extractParamData(ServerRequestInterface $request): CI\Input\InputData
protected function extractParamData(ServerRequestInterface $request): InputData
{
return new QueryParamsFromServerRequest($request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use ILIAS\UI\Implementation\Component\Input\Container\Container;
use ILIAS\UI\Component as C;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use Psr\Http\Message\ServerRequestInterface;
use ILIAS\UI\Implementation\Component\Input\PostDataFromServerRequest;
use ILIAS\UI\Implementation\Component\Input\NameSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
use ILIAS\Data\Factory as DataFactory;
use ILIAS\Data\Result;
use ILIAS\Refinery\Transformation;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Implementation\Component\Input\StackedInputData;
use ILIAS\Refinery\Factory as Refinery;
use ILIAS\UI\Component as C;

use ILIAS\UI\Implementation\Component\Input\ViewControl\HasInputGroup;

abstract class ViewControl extends Container implements I\ViewControl
Expand Down Expand Up @@ -109,7 +108,7 @@ public function getComponentInternalValues(
C\Input\Group $component = null,
array $input_values = []
): array {
if(is_null($component)) {
if (is_null($component)) {
$component = $this->getInputGroup();
}
foreach ($component->getInputs() as $input) {
Expand All @@ -119,7 +118,7 @@ public function getComponentInternalValues(
if ($input instanceof HasInputGroup) {
$input_values = $this->getComponentInternalValues($input->getInputGroup(), $input_values);
}
if($name = $input->getName()) {
if ($name = $input->getName()) {
$input_values[$input->getName()] = $input->getValue();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,9 +16,12 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\UI\Implementation\Component\Input;

use Iterator;
use ILIAS\UI\Component\Input\InputData;

/**
* @author Thibeau Fuhrer <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use ILIAS\UI\Component as C;
use ILIAS\UI\Implementation\Component\JavaScriptBindable;
use ILIAS\UI\Implementation\Component\Triggerer;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\Refinery\Constraint;
use Closure;
use LogicException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use ILIAS\UI\Component\Signal;
use ILIAS\UI\Implementation\Component\JavaScriptBindable;
use ILIAS\UI\Implementation\Component\Triggerer;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\Data\Result;
use Generator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use ILIAS\UI\Implementation\Component\Input\DynamicInputDataIterator;
use ILIAS\UI\Implementation\Component\Input\DynamicInputsNameSource;
use ILIAS\UI\Implementation\Component\Input\NameSource;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Component\Input\Container\Form\FormInput as FormInputInterface;
use ILIAS\UI\Component\Input\Field\HasDynamicInputs;
use ILIAS\Refinery\Factory as Refinery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use ILIAS\Refinery\Constraint;
use ILIAS\UI\Implementation\Component\JavaScriptBindable;
use ILIAS\UI\Implementation\Component\Triggerer;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Component\Input\Field as I;
use LogicException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace ILIAS\UI\Implementation\Component\Input\Field;

use ILIAS\UI\Component as C;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Implementation\Component\JavaScriptBindable;
use ILIAS\UI\Implementation\Component\Triggerer;
use ILIAS\Refinery\Constraint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use ILIAS\Refinery\Constraint;
use ILIAS\UI\Implementation\Component\JavaScriptBindable;
use ILIAS\UI\Implementation\Component\Triggerer;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Component\Input\Field as I;
use ILIAS\Language\Language;
use LogicException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use ILIAS\Data\Result\Ok;
use ILIAS\UI\Component as C;
use ILIAS\UI\Component\Signal;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use stdClass;
use ILIAS\Refinery\Constraint;
use InvalidArgumentException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use ILIAS\Data\Result;
use ILIAS\Data\Result\Ok;
use ILIAS\Language\Language;
use ILIAS\UI\Component\Input\InputData;

/**
* @author Thibeau Fuhrer <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use ILIAS\Refinery\Transformation;
use ILIAS\UI\Component\Signal;
use ILIAS\UI\Implementation\Component\ComponentHelper;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Implementation\Component\Input\NameSource;
use ILIAS\UI\Implementation\Component\JavaScriptBindable;
use ILIAS\UI\Implementation\Component\Triggerer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace ILIAS\UI\Implementation\Component\Input;

use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Component\Input\Input;
use ILIAS\Data\Result;
use ILIAS\UI\Implementation\Component\Input\NameSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use Psr\Http\Message\ServerRequestInterface;
use LogicException;
use ILIAS\UI\Component\Input\InputData;

/**
* Implements interaction of input element with post data from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace ILIAS\UI\Implementation\Component\Input;

use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use Psr\Http\Message\ServerRequestInterface;
use LogicException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace ILIAS\UI\Implementation\Component\Input;

use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use Psr\Http\Message\ServerRequestInterface;
use LogicException;

Expand All @@ -43,8 +43,8 @@ public function __construct(InputData ...$stack)

public function get(string $name)
{
foreach($this->stack as $input) {
if($input->has($name)) {
foreach ($this->stack as $input) {
if ($input->has($name)) {
return $input->get($name);
}
}
Expand All @@ -53,8 +53,8 @@ public function get(string $name)

public function getOr(string $name, $default)
{
foreach($this->stack as $input) {
if($input->has($name)) {
foreach ($this->stack as $input) {
if ($input->has($name)) {
return $input->get($name);
}
}
Expand All @@ -63,8 +63,8 @@ public function getOr(string $name, $default)

public function has($name): bool
{
foreach($this->stack as $input) {
if($input->has($name)) {
foreach ($this->stack as $input) {
if ($input->has($name)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use ILIAS\UI\Component\Input\Group;
use ILIAS\Refinery\Transformation;
use ILIAS\Data\Result;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Implementation\Component\Input\NameSource;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use ILIAS\UI\Implementation\Component\ReplaceSignal;
use ILIAS\UI\Component\Input\Field\Factory as FieldFactory;
use ILIAS\UI\Component\Input\Container\Form\FormInput;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Component\Component;
use ILIAS\UI\Component\Button;
use ILIAS\UI\Component\Signal;
Expand Down Expand Up @@ -182,6 +183,13 @@ public function withRequest(ServerRequestInterface $request): self
return $clone;
}

public function withInput(InputData $input_data): self
{
$clone = clone $this;
$clone->form = $clone->form->withInput($request);
return $clone;
}

/**
* @inheritdoc
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use ILIAS\UI\Implementation\Component\Input;
use ILIAS\UI\Component\Input\Container\Filter\FilterInput;
use ILIAS\UI\Implementation\Component\Input\NameSource;
use ILIAS\UI\Implementation\Component\Input\InputData;
use ILIAS\UI\Component\Input\InputData;
use ILIAS\UI\Implementation\Component\Input\Container\Filter\Filter;
use ILIAS\UI\Implementation\Component\SignalGenerator;
use ILIAS\Data;
Expand All @@ -45,7 +45,7 @@ public function getNewName(): string
class ConcreteFilter extends Filter
{
public array $inputs;
public ?Input\InputData $input_data = null;
public ?InputData $input_data = null;
protected Input\Field\Factory $input_factory;
protected Group $input_group;

Expand Down Expand Up @@ -80,12 +80,12 @@ public function __construct(
);
}

public function _extractParamData(ServerRequestInterface $request): Input\InputData
public function _extractParamData(ServerRequestInterface $request): InputData
{
return $this->extractParamData($request);
}

public function extractParamData(ServerRequestInterface $request): Input\InputData
public function extractParamData(ServerRequestInterface $request): InputData
{
if ($this->input_data !== null) {
return $this->input_data;
Expand Down
Loading

0 comments on commit 9b87723

Please sign in to comment.