diff --git a/README.md b/README.md index 4ea1b6f..db05c23 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Install 2. Move third\_party/nf\_categories\_field to expressionengine/third\_party 3. Move themes/third\_party/nf\_categories\_field to expressionengine/themes 4. Install the field type from the ExpressionEngine control panel +5. Create a new custom field and select the 'Categories' field type Field Settings -------------- @@ -47,22 +48,28 @@ Obviously if you set your field to 'Sync with Native Categories' then you can us ### Single Variables -When displaying the field on the front end, you can use the following single variables: +When displaying the field on the front end, you can use the following single variable: - `{field_name}` -This will either display a single category ID or a piped list (e.g. `1|3|17`). +This will either display a single category ID or a piped list if more than one category has been assigned (e.g. `1|3|17`). -- `{field_name:primary_category_id}` -- `{field_name:primary_category_name}` -- `{field_name:primary_category_url_title}` -- `{field_name:primary_category_parent_id}` +If you have enabled the 'Primary Category Assignment' option then you can access the various attributes of the primary category and the ID of it's parent (or itself if it has no parent) by appending the 'primary_category' modifier to the single field_name variable tag: -If you have enabled the 'Primary Category Assignment' option then you can access the ID and/or name or URL title of the primary category and the ID of it's parent (or itself if it has no parent) using these tags. +- `{field_name:primary_category:id}` +- `{field_name:primary_category:parent_id}` +- `{field_name:primary_category:name}` +- `{field_name:primary_category:url_title}` +- `{field_name:primary_category:description}` +- `{field_name:primary_category:image}` + +You can also return the primary category ID using the modifier with no attribute specified: + +- `{field_name:primary_category}` ### Variable Pair -You can also use a variable pair: +You can also use a field_name variable pair:
{field_name}
@@ -84,7 +91,9 @@ You also have access to one parameter:
Change Log
----------
-See Releases - https://github.com/ninefour/categories_field.ft.ee_addon/releases
+For release notes and instructions on upgrading from one version to another please check the releases page:
+
+https://github.com/ninefour/categories_field.ft.ee_addon/releases
Thanks
------
diff --git a/system/third_party/nf_categories_field/config.php b/system/third_party/nf_categories_field/config.php
index ffa357a..34cc925 100644
--- a/system/third_party/nf_categories_field/config.php
+++ b/system/third_party/nf_categories_field/config.php
@@ -12,7 +12,7 @@
if ( ! defined('NF_CF_NAME'))
{
define('NF_CF_NAME', 'Categories Field');
- define('NF_CF_VERSION', '1.0.9');
+ define('NF_CF_VERSION', '1.1.0');
define('NF_CF_DOCS', 'http://github.com/ninefour/categories_field.ft.ee_addon');
}
diff --git a/system/third_party/nf_categories_field/ft.nf_categories_field.php b/system/third_party/nf_categories_field/ft.nf_categories_field.php
index 9d32d78..36bc20f 100644
--- a/system/third_party/nf_categories_field/ft.nf_categories_field.php
+++ b/system/third_party/nf_categories_field/ft.nf_categories_field.php
@@ -3,7 +3,6 @@
// Get config file
require(PATH_THIRD.'nf_categories_field/config.php');
-
/**
* Categories Field Fieldtype
*
@@ -326,11 +325,7 @@ private function _display_field($data, $cell = FALSE)
$selected_primary = NULL;
$selected_primary_label = "";
- /*echo('');
- print_r($this->settings);
- exit;*/
-
- // If validation on the publish form fires we get an array
+ // If validation on the publish form fires we get an array back
if (is_array($data)) {
$selected = in_array($row[0], $data) ? 1 : 0;
@@ -364,7 +359,6 @@ private function _display_field($data, $cell = FALSE)
// Primary Category?
if (isset($this->settings['primary_cat']) AND $this->settings['primary_cat']) {
$selected_primary = ($row[0] == $selected_primary) ? 1 : 0;
- //echo($selected_primary);
if ($selected_primary) {
$selected_primary_label = 'Primary Category';
}
@@ -558,100 +552,106 @@ function replace_tag($data, $params = array(), $tagdata = FALSE) {
return $parsed;
}
- // {field_name:primary_category_id}
- function replace_primary_category_id($data, $params = array(), $tagdata = FALSE)
+ // {field_name:modifier} AND/OR {field_name:modifier:attribute}
+ function replace_tag_catchall($data, $params = array(), $tagdata = FALSE, $modifier)
{
// Establish Settings
$settings = (isset($this->settings['nf_categories_field'])) ? $this->settings['nf_categories_field'] : $this->settings;
$settings = $this->_default_settings($settings);
- $primary_cat_id = FALSE;
- // array_filter removes empty nodes, array_values re-indexes
- $categories = array_values(array_filter(explode($settings['delimiter'], $data)));
+ // Get modifier parts
+ $parts = explode(":", $modifier);
- if ($categories AND substr( $categories[0], 0, 1 ) === "p") {
- $primary_cat_id = ltrim($categories[0],'p');
- }
-
- return $primary_cat_id;
- }
-
- // {field_name:primary_category_name}
- function replace_primary_category_name($data, $params = array(), $tagdata = FALSE)
- {
+ // If part 1 is {field_name:primary_category...
+ if ($parts[0]=="primary_category") {
- // Establish Settings
- $settings = (isset($this->settings['nf_categories_field'])) ? $this->settings['nf_categories_field'] : $this->settings;
- $settings = $this->_default_settings($settings);
-
- $primary_cat_name = FALSE;
- // array_filter removes empty nodes, array_values re-indexes
- $categories = array_values(array_filter(explode($settings['delimiter'], $data)));
-
- if (substr( $categories[0], 0, 1 ) === "p") {
- $primary_cat_id = ltrim($categories[0],'p');
- $primary_cat = $this->_get_category_data(array($primary_cat_id));
+ $primary_category_id = FALSE;
+ $primary_category_parent_id = FALSE;
+ $primary_category_name = FALSE;
+ $primary_category_url_title = FALSE;
+ $primary_category_description = FALSE;
+ $primary_category_image = FALSE;
- if ($primary_cat[0]) {
- $primary_cat_name = $primary_cat[0]['category_name'];
- }
- }
+ // array_filter removes empty nodes, array_values re-indexes
+ $categories = array_values(array_filter(explode($settings['delimiter'], $data)));
- return $primary_cat_name;
- }
+ if ($categories AND substr( $categories[0], 0, 1 ) === "p") {
- // {field_name:primary_category_url_title}
- function replace_primary_category_url_title($data, $params = array(), $tagdata = FALSE)
- {
+ $primary_category_id = ltrim($categories[0],'p');
- // Establish Settings
- $settings = (isset($this->settings['nf_categories_field'])) ? $this->settings['nf_categories_field'] : $this->settings;
- $settings = $this->_default_settings($settings);
+ // If there is an attribute request {field_name:primary_category:something}
+ if (isset($parts[1])) {
- $primary_cat_url_title = FALSE;
- // array_filter removes empty nodes, array_values re-indexes
- $categories = array_values(array_filter(explode($settings['delimiter'], $data)));
+ // Get extra category data
+ $primary_category = $this->_get_category_data(array($primary_category_id));
- if (substr( $categories[0], 0, 1 ) === "p") {
- $primary_cat_id = ltrim($categories[0],'p');
- $primary_cat = $this->_get_category_data(array($primary_cat_id));
+ if (!is_array($primary_category[0])) {
+ return FALSE;
+ } else {
- if ($primary_cat[0]) {
- $primary_cat_url_title = $primary_cat[0]['category_url_title'];
- }
- }
+ switch ($parts[1]) {
+
+ // {field_name:primary_category:id}
+ case 'id':
+ return $primary_category_id;
+ break;
+
+ // {field_name:primary_category:name}
+ case 'name':
+ $primary_category_name = $primary_category[0]['category_name'];
+ return $primary_category_name;
+ break;
+
+ // {field_name:primary_category:url_title}
+ case 'url_title':
+ $primary_category_url_title = $primary_category[0]['category_url_title'];
+ return $primary_category_url_title;
+ break;
+
+ // {field_name:primary_category:description}
+ case 'description':
+ $primary_category_description = $primary_category[0]['category_description'];
+ return $primary_category_description;
+ break;
+
+ // {field_name:primary_category:image}
+ case 'image':
+ $primary_category_image = $primary_category[0]['category_image'];
+ return $primary_category_image;
+ break;
+
+ // {field_name:primary_category:parent_id}
+ case 'parent_id':
+ // If there's a parent return it's ID, else return this categories ID
+ if ($primary_category[0]['category_parent_id']==0) {
+ $primary_category_parent_id = $primary_category[0]['category_id'];
+ } else {
+ $primary_category_parent_id = $primary_category[0]['category_parent_id'];
+ }
+ return $primary_category_parent_id;
+ break;
- return $primary_cat_url_title;
- }
+ }
- // {field_name:primary_category_parent_id}
- function replace_primary_category_parent_id($data, $params = array(), $tagdata = FALSE)
- {
+ }
- // Establish Settings
- $settings = (isset($this->settings['nf_categories_field'])) ? $this->settings['nf_categories_field'] : $this->settings;
- $settings = $this->_default_settings($settings);
+ // Just return the default without any attribute preference
+ } else {
- $primary_cat_name = FALSE;
- // array_filter removes empty nodes, array_values re-indexes
- $categories = array_values(array_filter(explode($settings['delimiter'], $data)));
+ if ($categories AND substr( $categories[0], 0, 1 ) === "p") {
+ $primary_category_id = ltrim($categories[0],'p');
+ }
- if (substr( $categories[0], 0, 1 ) === "p") {
- $primary_cat_id = ltrim($categories[0],'p');
- $primary_cat = $this->_get_category_data(array($primary_cat_id));
+ // {field_name:primary_category}
+ return $primary_category_id;
- if ($primary_cat[0]) {
- // If there's a parent return it's ID, else return this categories ID
- if ($primary_cat[0]['category_parent_id']==0) {
- return $primary_cat[0]['category_id'];
- } else {
- return $primary_cat[0]['category_parent_id'];
}
+
}
+
}
- return;
}
/**
@@ -705,43 +705,10 @@ public function display_field($field_data)
return $this->_display_field($field_data);
}
- /**
- * Displays the field in matrix
- *
- * @param string
- * @return string
- */
- public function display_cell($cell_data)
- {
- return $this->_display_field($cell_data, TRUE);
- }
-
- /**
- * Displays the field in Low Variables
- *
- * @param string
- * @return string
- */
- public function display_var_field($var_data)
- {
- return $this->_display_field($var_data);
- }
-
- /**
- * Displays the field in Grid
- *
- * @param string
- * @return string
- */
- public function grid_display_field($grid_data)
- {
- return $this->_display_field($grid_data);
- }
-
// --------------------------------------------------------------------
/**
- * Allow in Grid
+ * Allowed Content Types
*
* @param string
* @return bool
@@ -749,13 +716,10 @@ public function grid_display_field($grid_data)
public function accepts_content_type($name)
{
return in_array($name, array(
- 'channel',
- 'grid',
- 'low_variables'
+ 'channel'
));
}
-
/**
* Include CSS theme to CP header
*
@@ -775,6 +739,7 @@ public function _include_theme_css($file, &$r = FALSE) {
}
}
}
+
/**
* Include JS theme to CP header
*