/** * Display the publish panel * * @param XMLElement $wrapper * @param null $data * @param null $error * @param null $prefix * @param null $postfix * @param null $entry_id * * @return void */ public function displayPublishPanel(XMLElement &$wrapper, $data = null, $error = null, $prefix = null, $postfix = null, $entry_id = null) { Extension_Selectbox_Link_Field_Image::appendAssets(); $fieldname = 'fields' . $prefix . '[' . $this->get('element_name') . ']' . $postfix; if ($this->get('allow_multiple_selection') == 'yes') { $fieldname .= '[]'; } $label = Widget::Label($this->get('label')); // Load the correct View: require_once EXTENSIONS . '/selectbox_link_field_image/views/view.' . $this->get('view') . '.php'; $class_name = 'SBLPView_' . ucfirst($this->get('view')); /** @var $view SBLPView */ $view = new $class_name(); $view_wrapper = new XMLElement('div', null, array('id' => 'sblp-view-' . $this->get('id'), 'class' => 'sblp-view sblp-view-' . $view->getHandle(), 'data-id' => $this->get('id'))); // edge case when new entry, required field but can't select entries if ($this->get('show_created') === '1' && $this->get('required') === 'yes' && is_null($entry_id)) { $view_wrapper->appendChild(new XMLElement('p', __('This field will be enabled after you create the entry.'), array('class' => 'help'))); } else { // Create new $view->generateCreate($label, $this); // Find entries $entry_ids = array(); if (!is_null($data['relation_id'])) { if (!is_array($data['relation_id'])) { $entry_ids = array($data['relation_id']); } else { $entry_ids = array_values($data['relation_id']); } } $options = array(); if ($this->get('required') != 'yes') { $options[] = array(null, false, null); } $states = $this->findOptions($entry_ids); if (!empty($states)) { foreach ($states as $s) { $group = array('label' => $s['name'], 'options' => array(), 'id' => $s['section']); foreach ($s['values'] as $id => $v) { if ($this->get('show_created') == 1) { // Check if this entry is created by it's parent: if (Symphony::Database()->fetchVar('count', 0, sprintf('SELECT COUNT(*) AS `count` FROM `tbl_sblp_created` WHERE `entry_id` = %d AND `created_id` = %d;', $entry_id, $id)) == 0) { // skip this one: continue; } } $group['options'][] = array($id, in_array($id, $entry_ids), General::sanitize($v)); } $options[] = $group; } } $view->generateView($view_wrapper, $fieldname, $options, $this); } $field_wrapper = new XMLElement('div'); $field_wrapper->appendChild($label); $field_wrapper->appendChild($view_wrapper); if (!is_null($error)) { $wrapper->appendChild(Widget::Error($field_wrapper, $error)); } else { $wrapper->appendChild($field_wrapper); } }
/** * Add some JavaScript and CSS to the header * * @return void */ public static function appendAssets() { if (self::$assets_loaded === false && class_exists('Administration') && Administration::instance() instanceof Administration && Administration::instance()->Page instanceof HTMLPage) { self::$assets_loaded = true; $page = Administration::instance()->Page; $page->addScriptToHead(URL . '/extensions/selectbox_link_field_image/assets/libraries/jquery-ui-1.8.16.custom.min.js'); $page->addScriptToHead(URL . '/extensions/selectbox_link_field_image/assets/libraries/inheritance.js'); $page->addScriptToHead(URL . '/extensions/selectbox_link_field_image/assets/libraries/sblp.js'); $page->addScriptToHead(URL . '/extensions/selectbox_link_field_image/assets/libraries/sblpview.js'); $page->addStylesheetToHead(URL . '/extensions/selectbox_link_field_image/assets/styles/sblp.css'); } }