public function listing() { // grab a taxonomy set from the content service $taxonomy_set = ContentService::getTaxonomiesByType($this->fetchParam('type', null)); // folders $folders = $this->fetchParam('folder', $this->fetchParam('folders', ltrim($this->fetchParam('from', URL::getCurrent()), "/"))); // now filter that down to just what we want $taxonomy_set->filter(array('folders' => $folders, 'show_hidden' => $this->fetchParam('show_hidden', false, null, true, false), 'show_drafts' => $this->fetchParam('show_drafts', false, null, true, false), 'since' => $this->fetchParam('since', null), 'until' => $this->fetchParam('until', null), 'min_count' => $this->fetchParam('min_count', 1, 'is_numeric'), 'show_future' => $this->fetchParam('show_future', false, null, true, false), 'show_past' => $this->fetchParam('show_past', true, null, true, false), 'conditions' => trim($this->fetchParam('conditions', null, false, false, false)), 'where' => trim($this->fetchParam('where', null, false, false, false)))); // sort as needed $taxonomy_set->sort($this->fetchParam('sort_by', 'name'), $this->fetchParam('sort_dir', 'asc')); // trim to limit the number of results $taxonomy_set->limit($this->fetchParam('limit', null, 'is_numeric')); // contextualize the urls to the given folder $taxonomy_set->contextualize($this->fetchParam('folder', null)); $output = $taxonomy_set->get(); // no results found, return so if (!count($output)) { return array('no_results' => true); } // results found, parse the tag loop with our content return Parse::tagLoop($this->content, $output, true, $this->context); }
public function render() { $field_data = $this->field_data; /* |-------------------------------------------------------------------------- | Multi-select |-------------------------------------------------------------------------- | | We need to set an empty array brace [] and add the "multiple" attribute | in the event we want to allow multi-selects. We also change the | plurality of the placeholder content. | */ $max_items = array_get($this->field_config, 'max_items', 'null'); $force_list = array_get($this->field_config, 'force_list', false); $multiple = array_get($this->field_config, 'multiple', true); $allow_blank = array_get($this->field_config, 'allow_blank', false); $placeholder = array_get($this->field_config, 'placeholder', false); if ($max_items === 1 && !$force_list) { $multiple = false; } $multiple_array_holder = $multiple ? '[]' : ''; $multiple_string = $multiple ? "multiple='multiple'" : ''; $placeholder_string = $placeholder ? "placeholder='$placeholder'" : ''; $suggestions = array(); /* |-------------------------------------------------------------------------- | Hardcoded list of options |-------------------------------------------------------------------------- | | Any list can contain a preset list of options available for suggestion, | exactly like how the Select fieldtype works. | */ if (isset($this->field_config['options'])) { $options = $this->field_config['options']; $suggestions = array_merge($suggestions, $options); } /* |-------------------------------------------------------------------------- | Entries & Pages |-------------------------------------------------------------------------- | | Fetch a list of pages and/or entries, using any existing fields as | labels and values | */ if (isset($this->field_config['content'])) { $config = $this->field_config['content']; $value = array_get($config, 'value', 'url'); $label = array_get($config, 'label', 'title'); $folder = array_get($config, 'folder'); $content_set = ContentService::getContentByFolders(array($folder)); $content_set->filter(array( 'show_hidden' => array_get($config, array('show_hidden', 'show_all'), false), // show_all is legacy 'show_drafts' => array_get($config, 'show_drafts', false), 'since' => array_get($config, 'since'), 'until' => array_get($config, 'until'), 'show_past' => array_get($config, 'show_past', true), 'show_future' => array_get($config, 'show_future', true), 'type' => array_get($config, 'type', 'entries'), 'conditions' => trim(array_get($config, 'conditions')) ) ); $entries = $content_set->get(); foreach ($entries as $entry) { $pieces = array(); foreach (Helper::ensureArray($label) as $label_part) { if (isset($entry[$label_part]) && isset($entry[$value])) { $pieces[] = $entry[$label_part]; } } $suggestions[$entry[$value]] = join(' – ', $pieces); } } /* |-------------------------------------------------------------------------- | Taxonomies |-------------------------------------------------------------------------- | | Single taxonomy types can be fetched from any folder. The taxonomy label | and value will be identical to ensure consistency with template logic | */ if (isset($this->field_config['taxonomy'])) { $taxonomy_type = array_get($this->field_config, 'taxonomy:type'); $folder = array_get($this->field_config, 'taxonomy:folder'); $taxonomy_set = ContentService::getTaxonomiesByType($taxonomy_type); // now filter that down to just what we want $taxonomy_set->filter(array( "min_count" => 1, "folders" => array($folder) )); $taxonomy_set->contextualize($folder); $taxonomies = $taxonomy_set->get(); foreach ($taxonomies as $key => $value) { $taxonomies[$key] = $value['name']; } $suggestions = array_merge($suggestions, $taxonomies); } /* |-------------------------------------------------------------------------- | Members |-------------------------------------------------------------------------- | | Fetch a list of members, using any existing fields as labels and values | */ if (isset($this->field_config['members'])) { $config = $this->field_config['members']; $value = array_get($config, 'value', '_uid'); $label = array_get($config, 'label', 'username'); $member_set = MemberService::getMembers(); $member_set->filter(array( 'role' => array_get($config, 'role') )); $members = $member_set->get(); foreach ($members as $key => $member) { if (isset($member[$label]) && isset($member[$value])) { $suggestions[$member[$value]] = $member[$label]; } } } /* |-------------------------------------------------------------------------- | Input HTML |-------------------------------------------------------------------------- | | Generate the HTML for the select field. A single, blank option is | needed if allow blank is true. | */ if ($max_items === null && $multiple === false) { $max_items = 1; } $options = json_encode(array( 'sortField' => 'text', 'maxItems' => $max_items, 'delimiter' => ',', 'create' => array_get($this->field_config, 'create', false), 'persist' => array_get($this->field_config, 'persist', true), 'hideSelected' => array_get($this->field_config, 'hide_selected', true), 'sortDirection' => array_get($this->field_config, 'sort_dir', 'asc'), 'plugins' => array('drag_drop'), 'dropdownParent' => 'body' )); $html = "<div id='$this->field_id' class='suggest-field-container' data-config='$options'>"; $html .= "<select name='{$this->fieldname}{$multiple_array_holder}' tabindex='{$this->tabindex}' $multiple_string $placeholder_string class='suggest'>\n"; $is_indexed = (array_values($suggestions) === $suggestions); // Preserve existing data's order if (is_array($field_data)) { $field_data = array_combine($field_data, $field_data); $suggestions = array_merge($field_data, $suggestions); } if ($allow_blank) { $html .= "<option value=''></option>\n"; } foreach ($suggestions as $value => $label) { $value = $is_indexed ? $label : $value; #allows setting custom values and labels if ($multiple && is_array($field_data) ) { $selected = in_array($value, $field_data) ? " selected " : ''; } else { $selected = $field_data == $value ? " selected " : ''; } $html .= '<option value="'. $value .'" ' . $selected .'>' . $label .'</option>'; } $html .= "</select>"; $html .= "<div class='count-placeholder'></div></div>"; $html .= "<script>$('#{$this->field_id}').statamicSuggest();</script>"; return $html; }
public function render() { /* |-------------------------------------------------------------------------- | Multi-select |-------------------------------------------------------------------------- | | We need to set an empty array brace [] and add the "multiple" attribute | in the event we want to allow multi-selects. We also change the | plurality of the placeholder content. | */ $multiple = array_get($this->field_config, 'multiple', true); $multiple_setting = $multiple ? "multiple" : ""; $multiple_array_holder = $multiple ? "[]" : ""; $default_placeholder = $multiple ? "Choose some options" : "Choose an option"; $placeholder = isset($this->field_config['placeholder']) ? $this->field_config['placeholder'] : $default_placeholder; $suggestions = array(); /* |-------------------------------------------------------------------------- | Hardcoded list of options |-------------------------------------------------------------------------- | | Any list can contain a preset list of options available for suggestion, | exactly like how the Select fieldtype works. | */ if (isset($this->field_config['options'])) { $options = $this->field_config['options']; $suggestions = array_merge($suggestions, $options); } /* |-------------------------------------------------------------------------- | Entries & Pages |-------------------------------------------------------------------------- | | Fetch a list of pages and/or entries, using any existing fields as | labels and values | */ if (isset($this->field_config['content'])) { $config = $this->field_config['content']; $value = array_get($config, 'value', 'url'); $label = array_get($config, 'label', 'title'); $folder = array_get($config, 'folder'); $content_set = ContentService::getContentByFolders(array($folder)); $content_set->filter(array('show_all' => array_get($config, 'show_all', false), 'since' => array_get($config, 'since'), 'until' => array_get($config, 'until'), 'show_past' => array_get($config, 'show_past', true), 'show_future' => array_get($config, 'show_future', true), 'type' => 'entries', 'conditions' => trim(array_get($config, 'conditions')))); $entries = $content_set->get(); // rd($entries); foreach ($entries as $key => $entry) { if (isset($entry[$label]) && isset($entry[$value])) { $suggestions[$entry[$value]] = $entry[$label]; } } } /* |-------------------------------------------------------------------------- | Taxonomies |-------------------------------------------------------------------------- | | Single taxonomy types can be fetched from any folder. The taxonomy label | and value will be identical to ensure consistency with template logic | */ if (isset($this->field_config['taxonomy'])) { $taxonomy_type = array_get($this->field_config, 'taxonomy:type'); $folder = array_get($this->field_config, 'taxonomy:folder'); $taxonomy_set = ContentService::getTaxonomiesByType($taxonomy_type); // now filter that down to just what we want $taxonomy_set->filter(array("folders" => array($folder))); $taxonomy_set->contextualize($folder); $taxonomies = $taxonomy_set->get(); foreach ($taxonomies as $key => $value) { $taxonomies[$key] = $value['name']; } $suggestions = array_merge($suggestions, $taxonomies); } /* |-------------------------------------------------------------------------- | Input HTML |-------------------------------------------------------------------------- | | Generate the HTML for the select field. A single, blank option is | needed if in single select mode. | */ $html = "<div class='input-suggest-wrap'>"; $html .= "<select name='{$this->fieldname}{$multiple_array_holder}' tabindex='{$this->tabindex}' {$multiple_setting} class='chosen-select' data-placeholder='{$placeholder}'>\n"; if (!$multiple) { $html .= "<option value=''></option>\n"; } foreach ($suggestions as $value => $label) { if ($multiple && is_array($this->field_data)) { $selected = in_array($value, $this->field_data) ? " selected " : ''; } else { $selected = $this->field_data == $value ? " selected " : ''; } $html .= "<option value='{$value}'{$selected}>{$label}</option>\n"; } $html .= "</select></div>"; return $html; }
public function render() { $field_data = $this->field_data; /* |-------------------------------------------------------------------------- | Multi-select |-------------------------------------------------------------------------- | | We need to set an empty array brace [] and add the "multiple" attribute | in the event we want to allow multi-selects. We also change the | plurality of the placeholder content. | */ $max_items = array_get($this->field_config, 'max_items', 'null'); $force_list = array_get($this->field_config, 'force_list', false); $multiple = array_get($this->field_config, 'multiple', true); $allow_blank = array_get($this->field_config, 'allow_blank', false); $placeholder = array_get($this->field_config, 'placeholder', false); if ($max_items === 1 && !$force_list) { $multiple = false; } $multiple_array_holder = $multiple ? '[]' : ''; $multiple_string = $multiple ? "multiple='multiple'" : ''; $placeholder_string = $placeholder ? "placeholder='{$placeholder}'" : ''; $suggestions = array(); /* |-------------------------------------------------------------------------- | Hardcoded list of options |-------------------------------------------------------------------------- | | Any list can contain a preset list of options available for suggestion, | exactly like how the Select fieldtype works. | */ if (isset($this->field_config['options'])) { $options = $this->field_config['options']; $suggestions = array_merge($suggestions, $options); } /* |-------------------------------------------------------------------------- | Entries & Pages |-------------------------------------------------------------------------- | | Fetch a list of pages and/or entries, using any existing fields as | labels and values | */ if (isset($this->field_config['content'])) { $config = $this->field_config['content']; $value = array_get($config, 'value', 'url'); $label = array_get($config, 'label', 'title'); $folder = array_get($config, 'folder'); $content_set = ContentService::getContentByFolders(array($folder)); $content_set->filter(array('show_hidden' => array_get($config, array('show_hidden', 'show_all'), false), 'show_drafts' => array_get($config, 'show_drafts', false), 'since' => array_get($config, 'since'), 'until' => array_get($config, 'until'), 'show_past' => array_get($config, 'show_past', true), 'show_future' => array_get($config, 'show_future', true), 'type' => array_get($config, 'type', 'entries'), 'conditions' => trim(array_get($config, 'conditions')))); $entries = $content_set->get(); foreach ($entries as $key => $entry) { if (isset($entry[$label]) && isset($entry[$value])) { $suggestions[$entry[$value]] = $entry[$label]; } } } /* |-------------------------------------------------------------------------- | Taxonomies |-------------------------------------------------------------------------- | | Single taxonomy types can be fetched from any folder. The taxonomy label | and value will be identical to ensure consistency with template logic | */ if (isset($this->field_config['taxonomy'])) { $taxonomy_type = array_get($this->field_config, 'taxonomy:type'); $folder = array_get($this->field_config, 'taxonomy:folder'); $taxonomy_set = ContentService::getTaxonomiesByType($taxonomy_type); // now filter that down to just what we want $taxonomy_set->filter(array("folders" => array($folder))); $taxonomy_set->contextualize($folder); $taxonomies = $taxonomy_set->get(); foreach ($taxonomies as $key => $value) { $taxonomies[$key] = $value['name']; } $suggestions = array_merge($suggestions, $taxonomies); } /* |-------------------------------------------------------------------------- | Members |-------------------------------------------------------------------------- | | Fetch a list of members, using any existing fields as labels and values | */ if (isset($this->field_config['members'])) { $config = $this->field_config['members']; $value = array_get($config, 'value', '_uid'); $label = array_get($config, 'label', 'username'); $member_set = MemberService::getMembers(); $member_set->filter(array('role' => array_get($config, 'role'))); $members = $member_set->get(); foreach ($members as $key => $member) { if (isset($member[$label]) && isset($member[$value])) { $suggestions[$member[$value]] = $member[$label]; } } } /* |-------------------------------------------------------------------------- | Input HTML |-------------------------------------------------------------------------- | | Generate the HTML for the select field. A single, blank option is | needed if allow blank is true. | */ $html = "<div id='{$this->field_id}'><select name='{$this->fieldname}{$multiple_array_holder}' tabindex='{$this->tabindex}' {$multiple_string} {$placeholder_string} class='suggest'>\n"; $is_indexed = array_values($suggestions) === $suggestions; // Preserve existing data's order if (is_array($field_data)) { $field_data = array_combine($field_data, $field_data); $suggestions = array_merge($field_data, $suggestions); } if ($allow_blank) { $html .= "<option value=''></option>\n"; } foreach ($suggestions as $value => $label) { $value = $is_indexed ? $label : $value; #allows setting custom values and labels if ($multiple && is_array($field_data)) { $selected = in_array($value, $field_data) ? " selected " : ''; } else { $selected = $field_data == $value ? " selected " : ''; } $html .= '<option value="' . $value . '" ' . $selected . '>' . $label . '</option>'; } $html .= "</select>"; $html .= "<div class='count-placeholder'></div></div>"; /* |-------------------------------------------------------------------------- | The JavaScript |-------------------------------------------------------------------------- | | Set the config options, instantiate Selectize, and so forth. | */ if ($max_items === null && $multiple === false) { $max_items = 1; } $options = json_encode(array('sortField' => 'text', 'maxItems' => $max_items, 'delimiter' => ',', 'create' => array_get($this->field_config, 'create', false), 'persist' => array_get($this->field_config, 'persist', true), 'hideSelected' => array_get($this->field_config, 'hide_selected', true), 'sortDirection' => array_get($this->field_config, 'sort_dir', 'asc'), 'plugins' => array('drag_drop'), 'dropdownParent' => 'body')); $html .= "\n <script>\n \$(function() {\n\n var selectize = \$('#{$this->field_id} select'),\n options = {$options};\n\n // @TODO: Rewrite in KO to avoid scoping issues in Grid fields\n // if (max_items != null) {\n // var count = (value === null) ? 0 : value.length,\n // value = selectize.val(),\n // max_items = {$max_items};\n // remaining = max_items - count,\n // placeholder = \$('#{$this->field_id} .count-placeholder');\n // \$.extend(options, {\n // 'onChange': function(value) {\n // count = (value === null) ? 0 : value.length;\n // remaining = max_items - count;\n // placeholder.text(remaining + ' remaining');\n // }\n // }\n // );\n // placeholder.text(remaining + ' remaining');\n // }\n\n \$(selectize).selectize({$options});\n });\n\n </script>\n "; return $html; }
/** * Generate files from a specified taxonomy type * * @param string $type The taxonomy type/name, ie. tags or categories * @param string $url The URL containing that needs modifying * @return array */ private function generateFilesFromTaxonomy($type, $url) { $taxonomies = array_keys(ContentService::getTaxonomiesByType($type)->get()); foreach ($taxonomies as $taxonomy) { $url = str_replace("{taxonomy:{$type}}", $taxonomy, $url); $files[] = $this->getFileData($url); } return $files; }