/** * @param string $key * * @return mixed */ public function getAttributeValue($key) { if (!$this->isTranslatableAttribute($key)) { return parent::getAttributeValue($key); } return $this->getTranslation($key, current_backend_language()); }
function current_language() { $whichEnd = session()->get('sharenjoy.whichEnd'); if ($whichEnd == 'backEnd') { return current_backend_language(); } elseif ($whichEnd == 'frontEnd') { if (config('cmsharenjoy.language_default')) { $language = config('cmsharenjoy.language_default'); if (array_key_exists(strtolower(Request::segment(1)), config('cmsharenjoy.language'))) { $language = strtolower(Request::segment(1)); } return $language; } } return null; }
public function processForm($formConfig, $input = array()) { if (count($formConfig)) { foreach ($formConfig as $name => $config) { // To get the options of select element from the Model if (isset($config['method'])) { $method = camel_case($config['method']); $formConfig[$name] = array_merge($formConfig[$name], $this->{$method}()); } // To get the options of select element from the Model if (isset($config['relation'])) { $id = isset($input['id']) ? $input['id'] : ''; $relation = camel_case($config['relation']); $formConfig[$name] = array_merge($formConfig[$name], $this->{$relation}($id)); } // If use key that the name is input of value otherwise use the $key if (isset($config['input']) && isset($input[$config['input']])) { $formConfig[$name]['value'] = $input[$config['input']]; } elseif (isset($input[$name])) { $formConfig[$name]['value'] = $input[$name]; } if (isset($config['columns'])) { foreach ($config['columns'] as $columnName => $columnValue) { if (isset($input[$columnName])) { $formConfig[$name]['columns'][$columnName]['value'] = $input[$columnName]; } if (property_exists($this, 'translatable')) { if (in_array($columnName, $this->translatable)) { if (isset($input[$columnName][current_backend_language()])) { $formConfig[$name]['columns'][$columnName]['value'] = $input[$columnName][current_backend_language()]; } else { $formConfig[$name]['columns'][$columnName]['value'] = null; } } } } } if (property_exists($this, 'translatable')) { if (in_array($name, $this->translatable)) { if (isset($input[$name][current_backend_language()])) { $formConfig[$name]['value'] = $input[$name][current_backend_language()]; } else { $formConfig[$name]['value'] = null; } } } } } return $formConfig; }
protected function parseTranslationFields(array $input) { $action = session('onAction'); if (property_exists($this, 'translatable') && ($action == 'create' || $action == 'update')) { foreach ($this->translatable as $name) { if (isset($input[$name][current_backend_language()])) { $input[$name] = $input[$name][current_backend_language()]; } else { $input[$name] = null; } } } return $input; }