本文整理汇总了PHP中FabrikWorker::validElementName方法的典型用法代码示例。如果您正苦于以下问题:PHP FabrikWorker::validElementName方法的具体用法?PHP FabrikWorker::validElementName怎么用?PHP FabrikWorker::validElementName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FabrikWorker
的用法示例。
在下文中一共展示了FabrikWorker::validElementName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Method to validate the form data.
*
* @param JForm $form The form to validate against.
* @param array $data The data to validate.
* @param string $group The name of the field group to validate.
*
* @see JFormRule
* @see JFilterInput
*
* @return mixed Array of filtered data if valid, false otherwise.
*/
public function validate($form, $data, $group = null)
{
$ok = parent::validate($form, $data);
$input = $this->app->input;
// Standard jForm validation failed so we shouldn't test further as we can't be sure of the data
if (!$ok) {
return false;
}
$db = FabrikWorker::getDbo(true);
$elementModel = $this->getElementPluginModel($data);
$nameChanged = $data['name'] !== $elementModel->getElement()->name;
$elementModel->getElement()->bind($data);
$listModel = $elementModel->getListModel();
if ($data['id'] == '') {
// Have to forcefully set group id otherwise listmodel id is blank
$elementModel->getElement()->group_id = $data['group_id'];
if ($listModel->canAddFields() === false && $listModel->noTable() === false) {
$this->setError(FText::_('COM_FABRIK_ERR_CANT_ADD_FIELDS'));
}
if (!FabrikWorker::validElementName($data['name'])) {
$this->setError(FText::_('COM_FABRIK_RESERVED_NAME_USED'));
}
} else {
if ($listModel->canAlterFields() === false && $nameChanged && $listModel->noTable() === false) {
$this->setError(FText::_('COM_FABRIK_ERR_CANT_ALTER_EXISTING_FIELDS'));
}
if ($nameChanged && !FabrikWorker::validElementName($data['name'], false)) {
$this->setError(FText::_('COM_FABRIK_RESERVED_NAME_USED'));
}
}
$listModel = $elementModel->getListModel();
/**
* Test for duplicate names
* un-linking produces this error
*/
if (!$input->get('unlink', false) && (int) $data['id'] === 0) {
/**
* @FIXME - if a repeat group is created through the Group settings, we don't add the auto-created
* table to the #_fabrik_lists table, so the following query obviously doesn't find it ... so we
* barf when creating element in the repeat group with a "duplicate name", even though it's going
* to be on a separate table.
*/
$query = $db->getQuery(true);
$query->select('t.id')->from('#__{package}_joins AS j');
$query->join('INNER', '#__{package}_lists AS t ON j.table_join = t.db_table_name');
$query->where('group_id = ' . (int) $data['group_id'] . ' AND element_id = 0');
$db->setQuery($query);
$joinTblId = (int) $db->loadResult();
$ignore = array($data['id']);
if ($joinTblId === 0) {
if ($listModel->fieldExists($data['name'], $ignore)) {
$this->setError(FText::_('COM_FABRIK_ELEMENT_NAME_IN_USE'));
}
} else {
/** @var FabrikFEModelList $joinListModel */
$joinListModel = JModelLegacy::getInstance('list', 'FabrikFEModel');
$joinListModel->setId($joinTblId);
$joinEls = $joinListModel->getElements();
foreach ($joinEls as $joinEl) {
if ($joinEl->getElement()->name == $data['name']) {
$ignore[] = $joinEl->getElement()->id;
}
}
if ($joinListModel->fieldExists($data['name'], $ignore)) {
$this->setError(FText::_('COM_FABRIK_ELEMENT_NAME_IN_USE'));
}
}
}
// Strip <p> tag from label
$data['label'] = JString::str_ireplace(array('<p>', '</p>'), '', $data['label']);
return count($this->getErrors()) == 0 ? $data : false;
}