function handleSave($populate = true) { if ($populate) { $this->_populateFromRequest(); if (isset($_REQUEST['subpanel_title']) && isset($_REQUEST['subpanel_title_key'])) { $authenticatedUserLanguage = !empty($_SESSION['authenticated_user_language']) ? $_SESSION['authenticated_user_language'] : false; $selected_lang = !empty($_REQUEST['selected_lang']) ? $_REQUEST['selected_lang'] : $authenticatedUserLanguage; if (empty($selected_lang)) { $selected_lang = $GLOBALS['sugar_config']['default_language']; } require_once 'modules/ModuleBuilder/parsers/parser.label.php'; $labelParser = new ParserLabel($_REQUEST['view_module'], isset($_REQUEST['view_package']) ? $_REQUEST['view_package'] : null); $labelParser->addLabels($selected_lang, array($_REQUEST['subpanel_title_key'] => remove_xss(from_html($_REQUEST['subpanel_title']))), $_REQUEST['view_module']); } } // Bug 46291 - Missing widget_class for edit_button and remove_button foreach ($this->_viewdefs as $key => $def) { if (isset($this->_fielddefs[$key]['widget_class'])) { $this->_viewdefs[$key]['widget_class'] = $this->_fielddefs[$key]['widget_class']; } } $defs = $this->restoreInvisibleFields($this->_invisibleFields, $this->_viewdefs); // unlike our parent, do not force the field names back to upper case $defs = $this->makeRelateFieldsAsLink($defs); $this->implementation->deploy($defs); }
function save($df) { $this->type = 'varchar'; require_once 'modules/ModuleBuilder/parsers/parser.label.php'; $parser = new ParserLabel($df->getModuleName(), $df->getPackageName()); foreach (array('City', 'State', 'PostalCode', 'Country') as $addressFieldName) { $systemLabel = strtoupper("LBL_" . $this->name . '_' . $addressFieldName); $parser->handleSave(array("label_" . $systemLabel => $this->label_value . ' ' . $addressFieldName), $GLOBALS['current_language']); $addressField = new TemplateField(); $addressField->len = $addressFieldName == 'PostalCode' ? 20 : 100; $addressField->name = $this->name . '_' . strtolower($addressFieldName); $addressField->label = $addressField->vname = $systemLabel; $addressField->save($df); } // finally save the base street address field parent::save($df); }
function save($df) { // Bug 58560 - Set the group name since addresses are part of a group $this->group = $df->getDBName($this->name); require_once 'modules/ModuleBuilder/parsers/parser.label.php'; $parser = new ParserLabel($df->getModuleName(), $df->getPackageName()); // Clean up the labels so they more accurately reflect the actual field if (!empty($this->label_value)) { $labelValue = $this->label_value; } else { $labelValue = empty($_REQUEST['labelValue']) ? '' : $_REQUEST['labelValue']; } // If there is a label to use, space it here for use below if (!empty($labelValue)) { $labelValue .= ' '; } // To prevent mutilple calls to the metadata api cache rebuilder, queue MetaDataManager::enableCacheRefreshQueue(); // To keep consistency with OOTB address groups, add Street to the fields foreach (array('Street', 'City', 'State', 'PostalCode', 'Country') as $addressFieldName) { $systemLabel = strtoupper("LBL_" . $this->name . '_' . $addressFieldName); // Use the entered label value as a prefix instead of the field name $parser->handleSave(array("label_" . $systemLabel => $labelValue . $addressFieldName), $GLOBALS['current_language']); if ($addressFieldName === 'Street') { $addressField = new TemplateAddressStreet(); $addressField->len = 150; } else { $addressField = new TemplateField(); $addressField->len = $addressFieldName === 'PostalCode' ? 20 : 100; } $addressField->name = $this->name . '_' . strtolower($addressFieldName); $addressField->label = $addressField->vname = $systemLabel; // Bug 58560 - Add the group to this field so it gets written to the custom vardefs $addressField->group = $this->group; // Maintain unified search setting for 'Street' $addressField->supports_unified_search = $addressField == 'Street'; $addressField->save($df); } // Handle the metadata api update now MetaDataManager::runCacheRefreshQueue(); }
public function testLabelSaving() { $lang = 'en_us'; $test_module = 'Opportunities'; $test_label = 'LBL_ACCOUNT_NAME'; $mod_strings = return_module_language($lang, $test_module); $old_label = $mod_strings[$test_label]; $new_label = 'test ' . $old_label; // save the new label to the language file ParserLabel::addLabels($lang, array($test_label => $new_label), $test_module); // read the language file to get the new value include "custom/modules/{$test_module}/language/en_us.lang.php"; $this->assertEquals($new_label, $mod_strings[$test_label], 'Label not changed.'); }
function action_saveProperty() { require_once 'modules/ModuleBuilder/parsers/parser.label.php'; $modules = $_REQUEST['view_module']; if (!empty($_REQUEST['subpanel'])) { $modules = $_REQUEST['subpanel']; } $parser = new ParserLabel($modules, isset($_REQUEST['view_package']) ? $_REQUEST['view_package'] : null); // if no language provided, then use the user's current language which is most likely what they intended $language = isset($_REQUEST['selected_lang']) ? $_REQUEST['selected_lang'] : $GLOBALS['current_language']; $parser->handleSave($_REQUEST, $language); $json = getJSONobj(); echo $json->encode(array("east" => array("action" => "deactivate"))); }
/** * Save label for id field * * @param string $idLabelName * @param DynamicField $df */ protected function saveIdLabel($idLabelName, $df) { if ($df instanceof DynamicField) { $module = $df->module; } elseif ($df instanceof MBModule) { $module = $df->name; } else { Log::fatal('Unsupported DynamicField type'); } $viewPackage = isset($df->package) ? $df->package : null; $idLabelValue = string_format($GLOBALS['mod_strings']['LBL_RELATED_FIELD_ID_NAME_LABEL'], array($this->label_value, $GLOBALS['app_list_strings']['moduleListSingular'][$this->ext2])); $idFieldLabelArr = array("label_{$idLabelName}" => $idLabelValue); foreach (ModuleBuilder::getModuleAliases($module) as $moduleName) { if ($df instanceof DynamicField) { $parser = new ParserLabel($moduleName, $viewPackage); $parser->handleSave($idFieldLabelArr, $GLOBALS['current_language']); } elseif ($df instanceof MBModule) { $df->setLabel($GLOBALS['current_language'], $idLabelName, $idLabelValue); $df->save(); } } }
/** * Adds a label to the module's mod_strings for the current language * Note that the system label name * * @param string $displayLabel The label value to be displayed * @return string The core of the system label name - returns currency_id5 for example, when the full label would then be LBL_CURRENCY_ID5 * TODO: Only the core is returned for historical reasons - switch to return the real system label */ function addLabel($displayLabel) { $mod_strings = return_module_language($GLOBALS['current_language'], $this->module); $limit = 10; $count = 0; $field_key = $this->getDBName($displayLabel, false); $systemLabel = $field_key; if (!$this->use_existing_labels) { // use_existing_labels defaults to false in this module; as of today, only set to true by ModuleInstaller.php while (isset($mod_strings[$systemLabel]) && $count <= $limit) { $systemLabel = $field_key . "_{$count}"; $count++; } } $selMod = !empty($_REQUEST['view_module']) ? $_REQUEST['view_module'] : $this->module; require_once 'modules/ModuleBuilder/parsers/parser.label.php'; $parser = new ParserLabel($selMod, isset($_REQUEST['view_package']) ? $_REQUEST['view_package'] : null); $parser->handleSave(array('label_' . $systemLabel => $displayLabel), $GLOBALS['current_language']); return $systemLabel; }
/** * For a particular module, rename any relevant module strings that need to be replaced. * * @param string $moduleName The name of the module to be renamed. * @param $replacementLabels * @return void */ private function changeModuleModStrings($moduleName, $replacementLabels) { $GLOBALS['log']->info("Begining to change module labels for: {$moduleName}"); $currentModuleStrings = return_module_language($this->selectedLanguage, $moduleName); $labelKeysToReplace = array(array('name' => 'LNK_NEW_RECORD', 'type' => 'plural'), array('name' => 'LNK_LIST', 'type' => 'plural'), array('name' => 'LNK_NEW_###MODULE_SINGULAR###', 'type' => 'singular'), array('name' => 'LNK_###MODULE_SINGULAR###_LIST', 'type' => 'plural'), array('name' => 'LNK_###MODULE_SINGULAR###_REPORTS', 'type' => 'singular'), array('name' => 'LNK_IMPORT_VCARD', 'type' => 'singular'), array('name' => 'LNK_IMPORT_###MODULE_PLURAL###', 'type' => 'plural'), array('name' => 'MSG_SHOW_DUPLICATES', 'type' => 'singular', 'case' => 'both'), array('name' => 'LBL_SAVE_###MODULE_SINGULAR###', 'type' => 'singular'), array('name' => 'LBL_LIST_FORM_TITLE', 'type' => 'singular'), array('name' => 'LBL_SEARCH_FORM_TITLE', 'type' => 'singular')); $replacedLabels = array(); foreach ($labelKeysToReplace as $entry) { $formattedLanguageKey = $this->formatModuleLanguageKey($entry['name'], $replacementLabels); //If the static of dynamic key exists it should be replaced. if (isset($currentModuleStrings[$formattedLanguageKey])) { $oldStringValue = $currentModuleStrings[$formattedLanguageKey]; $replacedLabels[$formattedLanguageKey] = $this->replaceSingleLabel($oldStringValue, $replacementLabels, $entry); if (isset($entry['case']) && $entry['case'] == 'both') { $replacedLabels[$formattedLanguageKey] = $this->replaceSingleLabel($replacedLabels[$formattedLanguageKey], $replacementLabels, $entry, 'strtolower'); } } } //Save all entries ParserLabel::addLabels($this->selectedLanguage, $replacedLabels, $moduleName); $this->renamedModules[$moduleName] = true; }
function handleSave($populate = true) { if ($populate) { $this->_populateFromRequest(); if (isset($_REQUEST['subpanel_title']) && isset($_REQUEST['subpanel_title_key'])) { $selected_lang = !empty($_REQUEST['selected_lang']) ? $_REQUEST['selected_lang'] : $_SESSION['authenticated_user_language']; if (empty($selected_lang)) { $selected_lang = $GLOBALS['sugar_config']['default_language']; } require_once 'modules/ModuleBuilder/parsers/parser.label.php'; $labelParser = new ParserLabel($_REQUEST['view_module'], isset($_REQUEST['view_package']) ? $_REQUEST['view_package'] : null); $labelParser->addLabels($selected_lang, array($_REQUEST['subpanel_title_key'] => $_REQUEST['subpanel_title']), $_REQUEST['view_module']); } } $this->implementation->deploy($this->restoreInvisibleFields($this->_invisibleFields, $this->_viewdefs)); // unlike our parent, do not force the field names back to upper case }
public function tearDown() { ParserLabel::addLabels($this->_lang, array($this->_test_label => $this->_old_label), $this->_test_module); }
/** * Rebuilds extensions and language files for this language and module * * @param string $language The language to rebuild extensions for * @param string $moduleName The name of the module whose extensions are being rebuilt */ protected static function rebuildLanguageExtensions($language, $moduleName) { if (empty(self::$moduleInstaller)) { self::$moduleInstaller = new ModuleInstaller(); self::$moduleInstaller->silent = true; } self::$moduleInstaller->rebuild_extensions(array($moduleName), array('languages')); // While this *is* called from rebuild_extensions, it doesn't do anything // there because there is no language or module provided to it. This fixes // that. self::$moduleInstaller->rebuild_languages(array($language => $language), array($moduleName)); }
public function tearDown() { ParserLabel::removeLabel($GLOBALS['current_language'], $this->idLabelName, $GLOBALS['mod_strings'][$this->idLabelName], $this->module); SugarTestHelper::tearDown(); parent::tearDown(); }