'Languages Support - Tabs', 'version' => 111, 'summary' => 'Organizes multi-language fields into tabs for a cleaner easier to use interface.', 'author' => 'adamspruijt, ryan', 'singular' => true, 'autoload' => "template=admin", 'requires' => 'LanguageSupportFields' ); } /** * Temporary storage of tabs created from addTab() method * * @var array of strings * */ protected $tabs = array(); /** * Add hooks, setup JS config, and determine active tab * */ public function ready() { if($this->wire('page')->template != 'admin') return; $this->addHookAfter('InputfieldForm::render', $this, 'hookRenderInputfieldForm'); $language = null; // allow for specifying language in your "edit" page link, from front-end // so if you want to focus on the Spanish tabs when the user clicks "edit" // from /es/path/to/page/, then you can by using a page edit link like: // Edit $id = (int) $this->input->get->language; if($id) $language = $this->languages->get($id); // if language is not specified as a GET variable, then use the user's language if(!$language || !$language->id) $language = $this->user->language; // determine the index of the tab for the user's language $activeTab = 0; foreach($this->languages as $index => $lang) { if($lang->id == $language->id) $activeTab = $index; } $settings = array( 'labelOpen' => $this->_('Expand Language Tabs'), 'labelClose' => $this->_('Collapse/Convert Back to Tabs'), 'activeTab' => $activeTab, ); $this->config->js('LanguageTabs', $settings); } /** * Init language tabs in form immediately after form render * * @param HookEvent $e * */ public function hookRenderInputfieldForm(HookEvent $e) { if(strpos($e->return, 'LanguageSupport') === false) return; $id = $e->object->attr('id'); $e->return .= ""; $this->config->scripts->add($this->config->urls->LanguageTabs . "LanguageTabs.js"); $this->config->styles->add($this->config->urls->LanguageTabs . "LanguageTabs.css"); } /** * Clear any stored tabs * */ public function resetTabs() { $this->tabs = array(); } /** * Add a new tab, to be later retrieved by renderTabs() * * @param Inputfield $inputfield * @param Language $language * */ public function addTab(Inputfield $inputfield, Language $language) { $class = $inputfield->isEmpty() ? " class='langTabEmpty'" : ""; $title = $this->wire('sanitizer')->entities1($language->get('title|name')); $id = $inputfield->attr('id'); $this->tabs[] = "