Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Last active December 17, 2015 19:59
Show Gist options
  • Save ziadoz/5664173 to your computer and use it in GitHub Desktop.
Save ziadoz/5664173 to your computer and use it in GitHub Desktop.
Perch Composite Slug Field Type
<?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);
}
}
@daletan
Copy link

daletan commented Aug 16, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment