Last active
December 17, 2015 19:59
-
-
Save ziadoz/5664173 to your computer and use it in GitHub Desktop.
Perch Composite Slug Field Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Composite Slug Field Type. | |
* | |
* File: PERCH_PATH/addons/fieldtypes/compslug/compslug.class.php | |
* Usage: <perch:content id="slug" type="compslug" for="lastname firstname" suppress="true" /> | |
* @author Jamie York | |
**/ | |
class PerchFieldType_compslug extends PerchFieldType | |
{ | |
public function render_inputs($details = array()) | |
{ | |
return ''; | |
} | |
public function get_raw($post = false, $Item = false) | |
{ | |
$fors = explode(' ', $this->Tag->for()); | |
$fors = array_map('trim', $fors); | |
$slug = array(); | |
foreach ($fors as $for) { | |
if (isset($post[$for])) { | |
$slug[] = $post[$for]; | |
} | |
} | |
if (count($slug) === 0) { | |
return ''; | |
} | |
$slug = array_map('stripslashes', $slug); | |
$slug = array_map('trim', $slug); | |
return PerchUtil::urlify(implode(' ', $slug)); | |
} | |
public function get_search_text($raw = false) | |
{ | |
if ($raw === false) { | |
$raw = $this->get_raw(); | |
} | |
$parts = explode('-', $raw); | |
return implode(' ', $parts); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for putting this up... You just saved me a couple of hours of having to do it myself! It ended up here: http://mplanninggroup.com/about.php