2014-09-02 15:39:21 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-09-02 15:39:21 +02:00
|
|
|
|
2014-11-14 10:57:14 +01:00
|
|
|
namespace Icinga\Forms\Config\Resource;
|
2014-09-02 15:39:21 +02:00
|
|
|
|
2015-03-06 09:49:15 +01:00
|
|
|
use Zend_Validate_Callback;
|
2014-09-02 15:39:21 +02:00
|
|
|
use Icinga\Web\Form;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Form class for adding/modifying file resources
|
|
|
|
*/
|
|
|
|
class FileResourceForm extends Form
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Initialize this form
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->setName('form_config_resource_file');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Form::createElements()
|
|
|
|
*/
|
|
|
|
public function createElements(array $formData)
|
|
|
|
{
|
2014-09-29 11:20:39 +02:00
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'name',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Resource Name'),
|
|
|
|
'description' => $this->translate('The unique name of this resource')
|
2014-09-29 11:20:39 +02:00
|
|
|
)
|
|
|
|
);
|
2014-09-03 12:21:31 +02:00
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'filename',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Filepath'),
|
|
|
|
'description' => $this->translate('The filename to fetch information from'),
|
2015-02-11 09:51:28 +01:00
|
|
|
'validators' => array('ReadablePathValidator')
|
2014-09-02 15:39:21 +02:00
|
|
|
)
|
|
|
|
);
|
2015-03-06 09:49:15 +01:00
|
|
|
$callbackValidator = new Zend_Validate_Callback(function ($value) {
|
|
|
|
return @preg_match($value, '') !== false;
|
|
|
|
});
|
|
|
|
$callbackValidator->setMessage(
|
|
|
|
$this->translate('"%value%" is not a valid regular expression.'),
|
|
|
|
Zend_Validate_Callback::INVALID_VALUE
|
|
|
|
);
|
2014-09-03 12:21:31 +02:00
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'fields',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Pattern'),
|
2015-03-06 09:49:15 +01:00
|
|
|
'description' => $this->translate('The pattern by which to identify columns.'),
|
|
|
|
'requirement' => $this->translate('The column pattern must be a valid regular expression.'),
|
|
|
|
'validators' => array($callbackValidator)
|
2014-09-03 12:21:31 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
2014-09-02 15:39:21 +02:00
|
|
|
}
|
|
|
|
}
|