/** * Add "LC widget settings" fieldset for the form * * :FIXME: to revize * * @param array &$form Form description * @param string $class LC widget class * @param string $label Widget class readable name * @param array $block Block description OPTIONAL * @param array $formInput Form input OPTIONAL * * @return void */ protected function addSettingsFieldset(array &$form, $class, $label, array $block = array(), array $formInput = array()) { // Get settings from LC $widget = $this->getHandler()->getWidget($class); if (isset($block['options']) && is_array($block['options'])) { $widget->setWidgetParams($block['options']); } // To prevent some unpredictable errors related to backslashes in element IDs $key = $this->getBlockName($class); if ($formInput && isset($formInput['lc_widget']) && isset($formInput['lc_widget'][$key])) { $widget->setWidgetParams($formInput['lc_widget'][$key]); } $settings = $widget->getWidgetSettings(); if ($settings) { $form[$key] = array('#type' => 'fieldset', '#title' => 'Parameters', '#attributes' => array('id' => $key)); $extendedItemsList = is_subclass_of($widget->getProtectedWidget(), 'XLite\\View\\ItemsList\\Product\\Customer\\ACustomer'); // Translate native LC options into Drupal format foreach ($settings as $name => $param) { $form[$key][$name] = array('#type' => $this->fieldTypesTranslationTable[$param->type], '#title' => t($param->label), '#default_value' => isset($block['options'][$name]) ? $block['options'][$name] : $param->value); $extendedAttributes = array(\XLite\View\ItemsList\Product\Customer\ACustomer::PARAM_ICON_MAX_WIDTH, \XLite\View\ItemsList\Product\Customer\ACustomer::PARAM_ICON_MAX_HEIGHT); if ('select' === $form[$key][$name]['#type']) { $form[$key][$name]['#options'] = $param->options; } elseif ($extendedItemsList && in_array($name, $extendedAttributes)) { $form[$key][$name]['#description'] = t('recommended: !size', array('!size' => 110)); } } if ($extendedItemsList) { if (!isset($form['#attached'])) { $form['#attached'] = array('js' => array()); } elseif (!isset($form['#attached']['js'])) { $form['#attached']['js'] = array(); } $path = \XLite\Core\Layout::getInstance()->getResourceFullPath('modules/CDev/DrupalConnector/blocks.js', \XLite::CUSTOMER_INTERFACE); $form['#attached']['js'][] = \XLite\View\AView::modifyResourcePath($path); // Display modes data $jsData = array(\XLite\View\ItemsList\Product\Customer\ACustomer::WIDGET_TYPE_SIDEBAR => \XLite\View\ItemsList\Product\Customer\ACustomer::getSidebarDisplayModes(), \XLite\View\ItemsList\Product\Customer\ACustomer::WIDGET_TYPE_CENTER => \XLite\View\ItemsList\Product\Customer\ACustomer::getCenterDisplayModes()); drupal_add_js('lcConnectorBlocks.' . $key . ' = ' . json_encode($jsData) . ';', 'inline'); // Recommended icons sizes $jsData = \XLite\View\ItemsList\Product\Customer\ACustomer::getIconSizes(); $lbl = t('recommended: !size'); drupal_add_js('lcConnectorRecommendedIconSizes.' . $key . ' = ' . json_encode($jsData) . ';' . PHP_EOL . 'var lcConnectorRecommendedLabel = \'' . $lbl . '\';', 'inline'); } } }