/** @var eZContentLanguage $language */ $language = eZContentLanguage::fetchByLocale($locale); if (!$language instanceof eZContentLanguage) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } $tag = eZTagsObject::fetchWithMainTranslation($tagID); if (!$tag instanceof eZTagsObject) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } if ($tag->attribute('main_tag_id') == 0) { return $Module->redirectToView('edit', array($tag->attribute('id'))); } $tagTranslation = eZTagsKeyword::fetch($tag->attribute('id'), $language->attribute('locale'), true); if (!$tagTranslation instanceof eZTagsKeyword) { $tagTranslation = new eZTagsKeyword(array('keyword_id' => $tag->attribute('id'), 'keyword' => '', 'language_id' => $language->attribute('id'), 'locale' => $language->attribute('locale'), 'status' => eZTagsKeyword::STATUS_DRAFT)); $tagTranslation->store(); $tag->updateLanguageMask(); } $tag = eZTagsObject::fetch($tagID, $language->attribute('locale')); if (!$tag instanceof eZTagsObject) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } $error = ''; if ($http->hasPostVariable('SaveButton')) { $newKeyword = trim($http->postVariable('TagEditKeyword', '')); if (empty($newKeyword)) { $error = ezpI18n::tr('extension/eztags/errors', 'Name cannot be empty.'); } if (empty($error) && eZTagsObject::exists($tag->attribute('id'), $newKeyword, $tag->attribute('parent_id'))) { $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that translation already exists in selected location.'); }
$error = ezpI18n::tr('extension/eztags/errors', 'Name cannot be empty.'); } if (empty($error) && eZTagsObject::exists(0, $newKeyword, $parentTag instanceof eZTagsObject ? $parentTag->attribute('id') : 0)) { $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that translation already exists in selected location.'); } if (empty($error)) { $db = eZDB::instance(); $db->begin(); $languageMask = eZContentLanguage::maskByLocale(array($language->attribute('locale')), $http->hasPostVariable('AlwaysAvailable')); $tag = new eZTagsObject(array('parent_id' => $parentTagID, 'main_tag_id' => 0, 'depth' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('depth') + 1 : 1, 'path_string' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('path_string') : '/', 'main_language_id' => $language->attribute('id'), 'language_mask' => $languageMask), $language->attribute('locale')); $tag->store(); $translation = new eZTagsKeyword(array('keyword_id' => $tag->attribute('id'), 'language_id' => $language->attribute('id'), 'keyword' => $newKeyword, 'locale' => $language->attribute('locale'), 'status' => eZTagsKeyword::STATUS_PUBLISHED)); if ($http->hasPostVariable('AlwaysAvailable')) { $translation->setAttribute('language_id', $translation->attribute('language_id') + 1); } $translation->store(); $tag->setAttribute('path_string', $tag->attribute('path_string') . $tag->attribute('id') . '/'); $tag->store(); $tag->updateModified(); /* Extended Hook */ if (class_exists('ezpEvent', false)) { ezpEvent::getInstance()->filter('tag/add', array('tag' => $tag, 'parentTag' => $parentTag)); } $db->commit(); return $Module->redirectToView('id', array($tag->attribute('id'))); } } $tpl = eZTemplate::factory(); $tpl->setVariable('parent_id', $parentTagID); $tpl->setVariable('language', $language); $tpl->setVariable('error', $error);
/** * Links the content object attribute and tag * * @static * * @param eZContentObjectAttribute $attribute * @param eZTagsObject $tagObject * @param string $keyword * @param string $locale */ private static function linkTag(eZContentObjectAttribute $attribute, eZTagsObject $tagObject, $keyword, $locale, $priority) { $languageID = eZContentLanguage::idByLocale($locale); if ($languageID === false) { return; } if ($locale == $attribute->attribute('language_code')) { if (!$tagObject->hasTranslation($locale)) { $tagKeywordObject = new eZTagsKeyword(array('keyword_id' => $tagObject->attribute('id'), 'language_id' => $languageID, 'keyword' => $keyword, 'locale' => $locale, 'status' => eZTagsKeyword::STATUS_PUBLISHED)); $tagKeywordObject->store(); $tagObject->updateLanguageMask(); } } $linkObject = new eZTagsAttributeLinkObject(array('keyword_id' => $tagObject->attribute('id'), 'objectattribute_id' => $attribute->attribute('id'), 'objectattribute_version' => $attribute->attribute('version'), 'object_id' => $attribute->attribute('contentobject_id'), 'priority' => $priority)); $linkObject->store(); }