* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} namespace Monitoring\Form\Command; use \Zend_Form_Element_Hidden; /** * Form to handle confirmations with a single value processed */ class CommandWithIdentifierForm extends CommandForm { /** * Identifier for data field * * @var string */ private $fieldName = 'objectid'; /** * Label for the field * * Human readable sting, must be translated before. * * @var string */ private $fieldLabel; /** * Setter for field label * * @param string $fieldLabel */ public function setFieldLabel($fieldLabel) { $this->fieldLabel = $fieldLabel; } /** * Getter for field label * * @return string */ public function getFieldLabel() { return $this->fieldLabel; } /** * Setter for field name * * @param string $fieldName */ public function setFieldName($fieldName) { $this->fieldName = $fieldName; } /** * Getter for field name * * @return string */ public function getFieldName() { return $this->fieldName; } /** * Create corresponding field for object configuration * @return Zend_Form_Element_Hidden */ private function createObjectField() { $value = $this->getRequest()->getParam($this->getFieldName()); $fieldLabel = $this->getFieldLabel(); $hiddenField = new Zend_Form_Element_Hidden($this->getFieldName()); $hiddenField->setValue($value); $hiddenField->setRequired(true); $hiddenField->addValidator( 'digits', true ); $hiddenField->removeDecorator('Label'); $hiddenField->addDecorator( 'Callback', array( 'callback' => function () use ($value, $fieldLabel) { return sprintf( '%s %s "%s"', $fieldLabel, t('is'), (isset($value)) ? $value : t('unset') ); } ) ); return $hiddenField; } /** * Interface method to build the form * @see CommandForm::create */ protected function create() { $this->addElement($this->createObjectField()); parent::create(); } }