Static function. Returns TRUE if the given name
is valid as an article type name.
public static IsValidFieldName ( string $p_name ) : boolean | ||
$p_name | string | |
Результат | boolean |
$articleTypeName = Input::Get('f_article_type'); $f_oldName = Input::Get('f_old_field_name'); $f_name = Input::Get('f_new_field_name'); if ($f_oldName == $f_name) { camp_html_goto_page("/$ADMIN/article_types/fields/?f_article_type=". urlencode($articleTypeName)); } $correct = true; $created = false; $errorMsgs = array(); if (empty($f_name)) { $correct = false; $errorMsgs[] = getGS('You must fill in the $1 field.','<B>'.getGS('Name').'</B>'); } else { $valid = ArticleType::IsValidFieldName($f_name); if (!$valid) { $correct = false; $errorMsgs[] = getGS('The $1 field may only contain letters and underscore (_) character.', '<B>' . getGS('Name') . '</B>'); } if ($correct) { $old_articleTypeField = new ArticleTypeField($articleTypeName, $f_oldName); if (!$old_articleTypeField->exists()) { $correct = false; $errorMsgs[] = getGS('The field $1 does not exist.', '<B>'.htmlspecialchars($f_oldName).'</B>'); } } if ($correct) { $articleTypeField = new ArticleTypeField($articleTypeName, $f_name);
public function testIsValidFieldName() { $this->assertTrue(ArticleType::IsValidFieldName('_a')); $this->assertTrue(ArticleType::IsValidFieldName('az')); $this->assertTrue(ArticleType::IsValidFieldName('a_')); $this->assertFalse(ArticleType::IsValidFieldName('')); $this->assertFalse(ArticleType::IsValidFieldName('_')); $this->assertFalse(ArticleType::IsValidFieldName('2')); $this->assertFalse(ArticleType::IsValidFieldName('_2')); $this->assertFalse(ArticleType::IsValidFieldName('2_')); $this->assertFalse(ArticleType::IsValidFieldName('a2')); $this->assertFalse(ArticleType::IsValidFieldName('a ')); }
} $articleTypeName = Input::Get('f_article_type'); $fieldName = trim(Input::Get('f_field_name')); $showInEditor = Input::Get('f_show_in_editor', 'int', 0); $fieldType = trim(Input::Get('f_article_field_type')); $rootTopicId = Input::Get('f_root_topic_id', 'int', 0); $isContent = Input::Get('f_is_content'); $precision = Input::Get('f_precision'); $editorSize = Input::Get('f_editor_size'); $editorSizeCustom = Input::Get('f_editor_size_custom'); $maxsize = Input::Get('f_maxsize'); $eventColor = Input::Get('f_event_color'); $field = new ArticleTypeField($articleTypeName, $fieldName); $correct = true; $errorMsgs = array(); if (!ArticleType::IsValidFieldName($fieldName)) { $errorMsgs[] = $translator->trans('The $1 must not be void and may only contain letters and underscore (_) character.', array('$1' => $translator->trans('Name')), 'article_type_fields'); $correct = false; } if ($field->exists()) { $errorMsgs[] = $translator->trans('The field $1 already exists.', array('$1' => '<B>' . urlencode($fieldName) . '</B>'), 'article_type_fields'); $correct = false; } $validTypes = array_keys(ArticleTypeField::DatabaseTypes()); if (!in_array($fieldType, $validTypes)) { $errorMsgs[] = $translator->trans('Invalid field type.', array(), 'article_type_fields'); $correct = false; } $article = new MetaArticle(); if ($article->has_property($fieldName) || method_exists($article, $fieldName)) { $correct = false;