protected function _buildWidgetOptions($schemafield, $attributes) { $partial = $schemafield->Partial; $filter = $schemafield->Filter; $is_multiple = $schemafield->isMultiple(); $is_quickadd = $schemafield->isQuickadd(); $is_sortable = $schemafield->isSortable(); $tag_direction = $schemafield->Direction; if (empty($tag_direction)) { $tag_direction = 'out'; } if (!empty($attributes['title'])) { $title = $attributes['title']; } else { $title = $schemafield->Title; } $value_opts = $schemafield->ValueOptions; $value_is_multiple = false; $pre_values = array(); $values_name = 'role'; if (!empty($value_opts)) { $value_mode = $value_opts->Mode; $values_name = $value_opts->Name; $value_is_multiple = $value_opts->isMultiple(); if ($value_mode != 'none') { $pre_values = $value_opts->Values; } } else { $value_mode = 'none'; } $title = StringUtils::jsEscape($title); $title_plural = $title; //StringUtils::pluralize($title); $opt[] = "\t\t\tLabel: '{$title}'"; $opt[] = "\t\t\tLabelPlural: '{$title_plural}'"; $opt[] = "\t\t\tActivateButtonLabel: '{$title}'"; $element = $partial->getTagElement(); if (empty($element)) { $element = '@' . $partial->getTagAspect(); } $quickaddelement = $element; if (!empty($attributes['quick-add-element'])) { $quickaddelement = $attributes['quick-add-element']; } $quickaddaction = 'node-quick-add'; if (!empty($attributes['quick-add-action'])) { $quickaddaction = $attributes['quick-add-action']; } if (!empty($attributes['search-parameters'])) { $str = array(); $params = explode('&', urldecode($attributes['search-parameters'])); foreach ($params as $param) { list($k, $v) = explode('=', $param, 2); $str[] = "'" . $k . "' : '" . $v . "'"; } $opt[] = "\t\t\tSearchParameters: {" . implode(',', $str) . "}"; } else { $opt[] = "\t\t\tSearchParameters: {'Elements.in' : '{$element}'}"; //Title keyword is auto-added by widget } if (!empty($attributes['search-url'])) { $opt[] = "\t\t\tSearchURL: '{$attributes['search-url']}'"; } if (!empty($attributes['show-element'])) { $opt[] = "\t\t\tShowElementInChosenList: true"; $opt[] = "\t\t\tShowElementInSearchResults: true"; } if ($tag_direction != 'out') { $opt[] = "\t\tTagDirection: '{$tag_direction}'"; } if (!empty($filter)) { $opt[] = "\t\tTagFilter: '" . $filter . "'"; } if ($is_quickadd) { $opt[] = "\t\t\tAllowQuickAdd: true"; $opt[] = "\t\t\tQuickAddNonce: '{% filter nonce?action={$quickaddaction} %}'"; $opt[] = "\t\t\tAddTagNonce: '{% filter nonce?action=node-add-tag %}'"; $opt[] = "\t\t\tReplaceNonce: '{% filter nonce?action=node-replace %}'"; $opt[] = "\t\t\tQuickAddElement : '{$quickaddelement}'"; $opt[] = "\t\t\tEditNonce: '{% filter nonce?action=node-edit %}'"; } if ($is_multiple) { $opt[] = "\t\t\tAllowMultiple: " . ($is_multiple ? 'true' : 'false') . ""; } if ($is_sortable) { $opt[] = "\t\t\tAllowReorderChosenList: " . ($is_sortable ? 'true' : 'false') . ""; } if ($value_mode != 'none') { $opt[] = "\t\tValueMode: '{$value_mode}'"; $opt[] = "\t\tAllowMultipleValues: " . ($value_is_multiple ? 'true' : 'false') . ""; if (!empty($pre_values)) { foreach ((array) $pre_values as $dname => $dvalue) { $array[] = array('value' => $dname, 'display' => $dvalue); } $opt[] = "\t\tValues: " . json_encode($array) . ""; } if (count($pre_values) == 1) { $opt[] = "\t\tShowExistingValues: false"; } else { if ($value_mode == 'typein') { $opt[] = "\t\tShowExistingValues: true"; } } } if (!empty($attributes['hide-tag-values'])) { $opt[] = "\t\t\tHideTagValues: true"; } if (!empty($attributes['tag-prepend'])) { if (StringUtils::strToBool($attributes['tag-prepend'])) { $opt[] = "\t\t\tTagPrepend: true"; } else { $opt[] = "\t\t\tTagPrepend: false"; } } return $opt; }
/** * Escapes the specified parameter in 'value' for use in javascript * * Expected Param: * value string * * @return string */ public function jsEscape() { if ($this->getParameter('value') == null) { return; } return StringUtils::jsEscape($this->getParameter('value')); }