Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust to CS fixer v3.2 rules #1670

Merged
merged 6 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/_unit-test/modal-reload.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

Header::addTo($app, ['Testing ModalExecutor reload']);

$modal = Modal::addTo($app->html, ['title' => 'Modal Executor', 'region' => 'Modals']);
$modal = Modal::addTo($app, ['title' => 'Modal Executor']);

$modal->set(function ($modal) {
ReloadTest::addTo($modal);
Expand Down
2 changes: 1 addition & 1 deletion demos/basic/button.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
// Creating your own button component example

/** @var Button $forkButtonClass */
$forkButtonClass = get_class(new class(0) extends Button { // need 0 argument here for constructor
$forkButtonClass = get_class(new class(0) /* need 0 argument here for constructor */ extends Button {
public function __construct($n)
{
Icon::addTo(Button::addTo($this, ['Forks', 'blue']), ['fork']);
Expand Down
69 changes: 43 additions & 26 deletions demos/interactive/virtual.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,88 @@

namespace Atk4\Ui\Demos;

use Atk4\Ui\Button;
use Atk4\Ui\Header;
use Atk4\Ui\LoremIpsum;
use Atk4\Ui\Message;
use Atk4\Ui\Modal;
use Atk4\Ui\Text;
use Atk4\Ui\View;
use Atk4\Ui\VirtualPage;

/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

// Demonstrate the use of Virtual Page.

// define virtual page.
$virtualPage = \Atk4\Ui\VirtualPage::addTo($app->layout, ['urlTrigger' => 'in']);
$virtualPage = VirtualPage::addTo($app->layout, ['urlTrigger' => 'in']);

// Add content to virtual page.
if (isset($_GET['p_id'])) {
\Atk4\Ui\Header::addTo($virtualPage, [$_GET['p_id']])->addClass('__atk-behat-test-car');
Header::addTo($virtualPage, [$_GET['p_id']])->addClass('__atk-behat-test-car');
}
\Atk4\Ui\LoremIpsum::addTo($virtualPage, ['size' => 1]);
$virtualPageButton = \Atk4\Ui\Button::addTo($virtualPage, ['Back', 'icon' => 'left arrow']);
LoremIpsum::addTo($virtualPage, ['size' => 1]);
$virtualPageButton = Button::addTo($virtualPage, ['Back', 'icon' => 'left arrow']);
$virtualPageButton->link('virtual.php');
$virtualPage->ui = 'grey inverted segment';

$msg = \Atk4\Ui\Message::addTo($app, ['Virtual Page']);
$modal = Modal::addTo($virtualPage);
$modal->set(function ($modal) {
Text::addTo($modal)->set('This is yet another modal');
LoremIpsum::addTo($modal, ['size' => 2]);
});
$button = Button::addTo($virtualPage)->set('Open Lorem Ipsum');
$button->on('click', $modal->show());

$msg = Message::addTo($app, ['Virtual Page']);
$msg->text->addParagraph('Virtual page content are not rendered on page load. They will ouptput their content when trigger.');
$msg->text->addParagraph('Click button below to trigger it.');

// button that trigger virtual page.
$btn = \Atk4\Ui\Button::addTo($app, ['More info on Car']);
$btn = Button::addTo($app, ['More info on Car']);
$btn->link($virtualPage->cb->getUrl() . '&p_id=Car');

$btn = \Atk4\Ui\Button::addTo($app, ['More info on Bike']);
$btn = Button::addTo($app, ['More info on Bike']);
$btn->link($virtualPage->cb->getUrl() . '&p_id=Bike');

// Test 1 - Basic reloading
\Atk4\Ui\Header::addTo($app, ['Virtual Page Logic']);
Header::addTo($app, ['Virtual Page Logic']);

$virtualPage = \Atk4\Ui\VirtualPage::addTo($app); // this page will not be visible unless you trigger it specifically
\Atk4\Ui\View::addTo($virtualPage, ['Contents of your pop-up here'])->addClass('ui header __atk-behat-test-content');
\Atk4\Ui\LoremIpsum::addTo($virtualPage, ['size' => 2]);
$virtualPage = VirtualPage::addTo($app); // this page will not be visible unless you trigger it specifically
View::addTo($virtualPage, ['Contents of your pop-up here'])->addClass('ui header __atk-behat-test-content');
LoremIpsum::addTo($virtualPage, ['size' => 2]);

Counter::addTo($virtualPage);
\Atk4\Ui\View::addTo($virtualPage, ['ui' => 'hidden divider']);
\Atk4\Ui\Button::addTo($virtualPage, ['Back', 'icon' => 'left arrow'])->link('virtual.php');
View::addTo($virtualPage, ['ui' => 'hidden divider']);
Button::addTo($virtualPage, ['Back', 'icon' => 'left arrow'])->link('virtual.php');

$bar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
\Atk4\Ui\Button::addTo($bar)->set('Inside current layout')->link($virtualPage->getUrl());
\Atk4\Ui\Button::addTo($bar)->set('On a blank page')->link($virtualPage->getUrl('popup'));
\Atk4\Ui\Button::addTo($bar)->set('No layout at all')->link($virtualPage->getUrl('cut'));
$bar = View::addTo($app, ['ui' => 'buttons']);
Button::addTo($bar)->set('Inside current layout')->link($virtualPage->getUrl());
Button::addTo($bar)->set('On a blank page')->link($virtualPage->getUrl('popup'));
Button::addTo($bar)->set('No layout at all')->link($virtualPage->getUrl('cut'));

\Atk4\Ui\Header::addTo($app, ['Inside Modal', 'subHeader' => 'Virtual page content can be display using JsModal Class.']);
Header::addTo($app, ['Inside Modal', 'subHeader' => 'Virtual page content can be display using JsModal Class.']);

$bar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
\Atk4\Ui\Button::addTo($bar)->set('Load in Modal')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut')));
$bar = View::addTo($app, ['ui' => 'buttons']);
Button::addTo($bar)->set('Load in Modal')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut')));

\Atk4\Ui\Button::addTo($bar)->set('Simulate slow load')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut') . '&slow=true'));
Button::addTo($bar)->set('Simulate slow load')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut') . '&slow=true'));
if (isset($_GET['slow'])) {
sleep(1);
}

\Atk4\Ui\Button::addTo($bar)->set('No title')->on('click', new \Atk4\Ui\JsModal(null, $virtualPage->getJsUrl('cut')));
Button::addTo($bar)->set('No title')->on('click', new \Atk4\Ui\JsModal(null, $virtualPage->getJsUrl('cut')));

\Atk4\Ui\View::addTo($app, ['ui' => 'hidden divider']);
$text = \Atk4\Ui\Text::addTo($app);
View::addTo($app, ['ui' => 'hidden divider']);
$text = Text::addTo($app);
$text->addParagraph('Can also be trigger from a js event, like clicking on a table row.');
$table = \Atk4\Ui\Table::addTo($app, ['celled' => true]);
$table->setModel(new SomeData());

$frame = \Atk4\Ui\VirtualPage::addTo($app);
$frame = VirtualPage::addTo($app);
$frame->set(function ($frame) {
\Atk4\Ui\Header::addTo($frame, ['Clicked row with ID = ' . ($_GET['id'] ?? '')]);
Header::addTo($frame, ['Clicked row with ID = ' . ($_GET['id'] ?? '')]);
});

$table->onRowClick(new \Atk4\Ui\JsModal('Row Clicked', $frame, ['id' => $table->jsRow()->data('id')]));
2 changes: 1 addition & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ private function outputResponseJson($data, array $headers = []): void
}

/**
* Generated html and js for modals attached to $html view.
* Generated html and js for portal view registered to app.
*/
private function getRenderedPortals(): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/Form/Control/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ protected function init(): void

if ($this->type === 'datetime' || $this->type === 'time') {
$this->options['enableTime'] = true;
$this->options['time_24hr'] = $this->options['time_24hr'] ?? $this->use24hrTimeFormat($this->options['altFormat'] ?? $this->options['dateFormat']);
$this->options['time_24hr'] ??= $this->use24hrTimeFormat($this->options['altFormat'] ?? $this->options['dateFormat']);
$this->options['noCalendar'] = ($this->type === 'time');

// Add seconds picker if set
$this->options['enableSeconds'] = $this->options['enableSeconds'] ?? $this->useSeconds($this->options['altFormat'] ?? $this->options['dateFormat']);
$this->options['enableSeconds'] ??= $this->useSeconds($this->options['altFormat'] ?? $this->options['dateFormat']);

// Allow edit if microseconds is set.
$this->options['allowInput'] = $this->options['allowInput'] ?? $this->allowMicroSecondsInput($this->options['altFormat'] ?? $this->options['dateFormat']);
$this->options['allowInput'] ??= $this->allowMicroSecondsInput($this->options['altFormat'] ?? $this->options['dateFormat']);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/Multiline.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ protected function getLookupProps(Field $field): array
$props['config']['search'] = true;
}

$props['config']['placeholder'] = $props['config']['placeholder'] ?? 'Select ' . $field->getCaption();
$props['config']['placeholder'] ??= 'Select ' . $field->getCaption();

$this->valuePropsBinding[$field->short_name] = [__CLASS__, 'setLookupOptionValue'];

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/ScopeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ protected function getLookupProps(Field $field): array
$props['search'] = true;
}

$props['placeholder'] = $props['placeholder'] ?? 'Select ' . $field->getCaption();
$props['placeholder'] ??= 'Select ' . $field->getCaption();

return $props;
}
Expand Down
2 changes: 1 addition & 1 deletion src/JsSse.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function sendBlock(string $id, string $data, string $name = null): void
}

$this->output('id: ' . $id . "\n");
if (strlen($name) > 0) {
if ($name !== null) {
$this->output('event: ' . $name . "\n");
}
$this->output($this->wrapData($data) . "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/Table/Column/ColorRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private function createGradientSingle(&$gradients, $hexFrom, $hexTo, $steps)

public function getTagAttributes($position, array $attr = []): array
{
$attr['style'] = $attr['style'] ?? '';
$attr['style'] ??= '';
$attr['style'] .= '{$_' . $this->short_name . '_color_rating}';

return parent::getTagAttributes($position, $attr);
Expand Down
2 changes: 1 addition & 1 deletion src/UserAction/ConfirmationExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function setAction(Model\UserAction $action): Modal
$this->action = $action;
$this->afterActionInit($action);

$this->title = $this->title ?? $action->getDescription();
$this->title ??= $action->getDescription();
$this->step = $this->stickyGet('step');

$this->actionInitialized = true;
Expand Down
2 changes: 1 addition & 1 deletion src/UserAction/ModalExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function setAction(Model\UserAction $action): View

// get necessary step need prior to execute action.
if ($this->steps = $this->getSteps($action)) {
$this->title = $this->title ?? $action->getDescription();
$this->title ??= $action->getDescription();

// get current step.
$this->step = $this->stickyGet('step') ?? $this->steps[0];
Expand Down
10 changes: 0 additions & 10 deletions src/VirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,10 @@ public function getHtml()
}
}

// Prepare modals in order to include them in VirtualPage.
$modalHtml = '';
foreach ($this->getApp()->html !== null ? $this->getApp()->html->elements : [] as $view) {
if ($view instanceof Modal) {
$modalHtml .= $view->getHtml();
$this->getApp()->layout->_js_actions = array_merge($this->getApp()->layout->_js_actions, $view->_js_actions);
}
}

$this->getApp()->layout->template->dangerouslySetHtml('Content', parent::getHtml());
$this->getApp()->layout->_js_actions = array_merge($this->getApp()->layout->_js_actions, $this->_js_actions);

$this->getApp()->html->template->dangerouslySetHtml('Content', $this->getApp()->layout->template->renderToHtml());
$this->getApp()->html->template->dangerouslySetHtml('Modals', $modalHtml);

$this->getApp()->html->template->dangerouslyAppendHtml('HEAD', $this->getApp()->layout->getJs());

Expand Down
2 changes: 2 additions & 0 deletions tests-behat/virtual-page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Feature: VirtualPage
Given I am on "interactive/virtual.php"
Then I click link 'More info on Car'
Then text in container using '.__atk-behat-test-car' should contains 'Car'
Then I press button "Open Lorem Ipsum"
Then Modal is open with text 'This is yet another modal'

Scenario:
Given I am on "interactive/virtual.php"
Expand Down