From 75fb9836222f150ab0b75a438d14b02dc44c34cc Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 25 Aug 2017 18:12:39 +0200 Subject: [PATCH] Forms: transform addHtmlHint into ipl-aware code --- application/forms/IcingaServiceForm.php | 89 +++++++++------------- application/forms/IcingaServiceSetForm.php | 4 +- application/forms/KickstartForm.php | 41 +++++----- library/Director/Util.php | 20 +++-- 4 files changed, 73 insertions(+), 81 deletions(-) diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php index 792e6bcd..f5ac3722 100644 --- a/application/forms/IcingaServiceForm.php +++ b/application/forms/IcingaServiceForm.php @@ -9,12 +9,15 @@ use Icinga\Module\Director\Web\Form\DirectorObjectForm; use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Objects\IcingaService; use Icinga\Module\Director\Objects\IcingaServiceSet; +use ipl\Html\Html; +use ipl\Html\Link; class IcingaServiceForm extends DirectorObjectForm { /** @var IcingaHost */ private $host; + /** @var IcingaServiceSet */ private $set; private $apply; @@ -80,10 +83,7 @@ class IcingaServiceForm extends DirectorObjectForm return; } - $this->addHtmlHint( - $this->getOverrideHint(), - array('name' => 'inheritance_hint') - ); + $this->addOverrideHint(); $group = $this->getDisplayGroup('custom_fields'); @@ -142,91 +142,78 @@ class IcingaServiceForm extends DirectorObjectForm ->setButtons(); } - protected function getOverrideHint() + protected function addOverrideHint() { - $view = $this->getView(); - if ($this->object && $this->object->usesVarOverrides()) { - return $this->translate( + $hint = $this->translate( 'This service has been generated in an automated way, but still' . ' allows you to override the following properties in a safe way.' ); - } - - if ($this->applyGenerated) { - return $view->escape(sprintf( + } elseif ($this->applyGenerated) { + $hint = Html::sprintf( $this->translate( 'This service has been generated using an apply rule, assigned where %s' ), - Filter::fromQueryString($this->applyGenerated->assign_filter) - )); - } - - if ($this->host && $this->set) { - return $this->translate( + (string) Filter::fromQueryString($this->applyGenerated->assign_filter) + ); + } elseif ($this->host && $this->set) { + $hint = $this->translate( 'This service belongs to a Service Set. Still, you might want' . ' to override the following properties for this host only.' ); - } - - if ($this->inheritedFrom) { - $msg = $view->escape($this->translate( + } elseif ($this->inheritedFrom) { + $msg = $this->translate( 'This service has been inherited from %s. Still, you might want' . ' to change the following properties for this host only.' - )); - - $name = $this->inheritedFrom; - $link = $view->qlink( - $name, - 'director/service', - array( - 'host' => $name, - 'name' => $this->object->object_name, - ), - array('data-base-target' => '_next') ); - return sprintf($msg, $link); + $name = $this->inheritedFrom; + $link = Link::create( + $name, + 'director/service', + [ + 'host' => $name, + 'name' => $this->object->getObjectName(), + ], + ['data-base-target' => '_next'] + ); + + $hint = Html::sprintf($msg, $link); } - $this->setSubmitLabel( - $this->translate('Override vars') - ); + $this->setSubmitLabel($this->translate('Override vars')); + + $this->addHtmlHint($hint, ['name' => 'inheritance_hint']); } protected function setupOnHostForSet() { - $view = $this->getView(); - $msg = $view->escape($this->translate( + $msg = $this->translate( 'This service belongs to the service set "%s". Still, you might want' . ' to change the following properties for this host only.' - )); + ); $name = $this->set->getObjectName(); - $link = $view->qlink( + $link = Link::create( $name, 'director/serviceset', - array( - 'name' => $name, - ), - array('data-base-target' => '_next') + ['name' => $name], + ['data-base-target' => '_next'] ); $this->addHtmlHint( - sprintf($msg, $link), - array('name' => 'inheritance_hint') + Html::sprintf($msg, $link), + ['name' => 'inheritance_hint'] ); $this->addElementsToGroup( - array('inheritance_hint'), + ['inheritance_hint'], 'custom_fields', 50, $this->translate('Custom properties') ); - $this->setSubmitLabel( - $this->translate('Override vars') - ); + $this->setSubmitLabel($this->translate('Override vars')); } protected function addAssignmentElements() diff --git a/application/forms/IcingaServiceSetForm.php b/application/forms/IcingaServiceSetForm.php index b695fee3..f966b8b6 100644 --- a/application/forms/IcingaServiceSetForm.php +++ b/application/forms/IcingaServiceSetForm.php @@ -86,9 +86,7 @@ class IcingaServiceSetForm extends DirectorObjectForm if (count($object->get('imports'))) { $this->addHtmlHint( - $this->getView()->escape( - $object->getResolvedProperty('description') - ) + $object->getResolvedProperty('description') ); } diff --git a/application/forms/KickstartForm.php b/application/forms/KickstartForm.php index 9a8600d1..dca92ee8 100644 --- a/application/forms/KickstartForm.php +++ b/application/forms/KickstartForm.php @@ -10,7 +10,8 @@ use Icinga\Module\Director\Db\Migrations; use Icinga\Module\Director\Objects\IcingaEndpoint; use Icinga\Module\Director\KickstartHelper; use Icinga\Module\Director\Web\Form\DirectorForm; -use Icinga\Module\Director\Web\Form\QuickForm; +use ipl\Html\Html; +use ipl\Html\Link; class KickstartForm extends DirectorForm { @@ -60,16 +61,17 @@ class KickstartForm extends DirectorForm } if (! $this->endpoint && $this->getDb()->hasDeploymentEndpoint()) { - $hint = sprintf($this->translate( - 'Your database looks good, you are ready to %s' - ), $this->getView()->qlink( - 'start working with the Icinga Director', - 'director', - null, - array('data-base-target' => '_main') - )); + $hint = Html::sprintf( + $this->translate('Your database looks good, you are ready to %s'), + Link::create( + 'start working with the Icinga Director', + 'director', + null, + ['data-base-target' => '_main'] + ) + ); - $this->addHtmlHint($hint, array('name' => 'HINT_ready')); + $this->addHtmlHint($hint, ['name' => 'HINT_ready']); $this->getDisplayGroup('config')->addElements( array($this->getElement('HINT_ready')) ); @@ -233,14 +235,15 @@ class KickstartForm extends DirectorForm $this->translate('This has to be a MySQL or PostgreSQL database') ); - $hint = $this->translate('Please click %s to create new DB resources'); - $link = $this->getView()->qlink( - $this->translate('here'), - 'config/resource', - null, - array('data-base-target' => '_main') - ); - $this->addHtmlHint(sprintf($hint, $link)); + $this->addHtmlHint(Html::sprintf( + $this->translate('Please click %s to create new DB resources'), + Link::create( + $this->translate('here'), + 'config/resource', + null, + ['data-base-target' => '_main'] + ) + )); } $this->setSubmitLabel($this->storeConfigLabel); @@ -308,7 +311,7 @@ class KickstartForm extends DirectorForm ) ); $this->addHtmlHint( - '
' . $config . '
', + Html::tag('pre', null, $config), array('name' => 'HINT_config_store') ); diff --git a/library/Director/Util.php b/library/Director/Util.php index 1b6f512f..8368bcb9 100644 --- a/library/Director/Util.php +++ b/library/Director/Util.php @@ -7,7 +7,8 @@ use Icinga\Data\ResourceFactory; use Icinga\Module\Director\Web\Form\QuickForm; use Icinga\Exception\NotImplementedError; use Icinga\Exception\ProgrammingError; -use Icinga\Web\Url; +use ipl\Html\Html; +use ipl\Html\Link; use Zend_Db_Expr; class Util @@ -173,14 +174,17 @@ class Util 'required' => true, )); - if (true && empty($list)) { + if (empty($list)) { if (self::hasPermission('config/application/resources')) { - $hint = $form->translate('Please click %s to create new resources'); - $link = sprintf( - '%s', - $form->translate('here') - ); - $form->addHtmlHint(sprintf($hint, $link)); + $form->addHtmlHint(Html::sprintf( + $form->translate('Please click %s to create new resources'), + Link::create( + $form->translate('here'), + 'config/resource', + null, + ['data-base-target' => '_main'] + ) + )); $msg = sprintf($form->translate('No %s resource available'), $type); } else { $msg = $form->translate('Please ask an administrator to grant you access to resources');