Skip to content

Commit

Permalink
setLayout -> initLayout (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkSide666 authored Mar 9, 2020
1 parent 68c9fb9 commit 80b86da
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ well as display of labels and structure around the fields themselves is not done
but another object - "Form Layout". This object is responsible for the field flow, presence
of labels etc.

.. php:method:: setLayout(FormLayout\Generic $layout)
.. php:method:: initLayout(FormLayout\Generic $layout)
Sets a custom FormLayout object for a form. If not specified then form will automatically
use FormLayout\Generic.
Expand Down
2 changes: 1 addition & 1 deletion docs/render.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Late initialization
When you create an application and select a Layout, the layout is automatically initialized::

$app = new \atk4\ui\App();
$app->setLayout('Centered');
$app->initLayout('Centered');

echo $app->layout->name; // present, because layout is initialized!

Expand Down
6 changes: 3 additions & 3 deletions docs/view.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ is executed it will be impossible to determine each view's position inside rende
// Still not sure if finished adding

$app = new \atk4\ui\App('My App');
$app->setLayout($top);
$app->initLayout($top);

// Calls init() for all elements recursively.

Expand All @@ -94,7 +94,7 @@ child elements. To make your execution more straightforward we recommend you to
App class first and then continue with Layout initialization::

$app = new \atk4\ui\App('My App');
$top = $app->setLayout(new \atk4\ui\View(['ui'=>'segments']));
$top = $app->initLayout(new \atk4\ui\View(['ui'=>'segments']));

$middle = $top->add(new \atk4\ui\View(['ui'=>'segment', 'red']);

Expand All @@ -103,7 +103,7 @@ App class first and then continue with Layout initialization::
Finally, if you prefer a more consise code, you can also use the following format::

$app = new \atk4\ui\App('My App');
$top = $app->setLayout('View', ['ui'=>'segments']);
$top = $app->initLayout('View', ['ui'=>'segments']);

$middle = $top->add('View', ['ui'=>'segment', 'red']);

Expand Down
3 changes: 2 additions & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ public function normalizeClassNameApp($name, $prefix = ''): ?string
public function add($seed, $region = null)
{
if (!$this->layout) {
throw new Exception(['If you use $app->add() you should first call $app->setLayout()']);
throw (new Exception('App layout is missing'))
->addSolution('If you use $app->add() you should first call $app->initLayout()');
}

return $this->layout->add($seed, $region);
Expand Down
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Form extends View //implements \ArrayAccess - temporarily so that our buil

/**
* Will point to the Save button. If you don't want to have save button, then set this to false
* or destroy it. Initialized by setLayout().
* or destroy it. Initialized by initLayout().
*
* @var Button|array|false Button object, seed or false to not show button at all
*/
Expand Down

0 comments on commit 80b86da

Please sign in to comment.