File: D:/HostingSpaces/SBogers93/fitale.nl/workbench/komma/kms/src/Komma/Kms/Core/Attributes/KmsRoute.php
<?php
/**
* Short description for the file.
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Kms\Core\Attributes;
use Komma\Kms\Languages\Language;
use View;
class KmsRoute extends KmsAttribute{
public $label;
public $placeholder;
public $structure;
public $slugField;
public $parentField;
public $restRoute;
function __construct($key, $value, array $options = [], array $errors = [], $languageId = null, $section = null)
{
parent::__construct($key, $value, $options, $errors, $languageId, $section);
$this->label = $this->getOption('label', $key);
$this->placeholder = $this->getOption('placeholder', $key);
$this->structure = $this->getOption('structure', $key);
$this->slugField = $this->getOption('slugField', $key);
$this->parentField = $this->getOption('parentField', $key);
$this->restRoute = $this->getOption('rest_route');
}
public function getValidation()
{
// Get validation
$validation = $this->getOption('validation');
// Get current entity
$entity = $this->section->getEntity();
// For the rule "different:[[routesInOtherLanguages]]", check if we have other languages
if( ! method_exists($entity, 'getKeyInOtherLanguages'));
$routesInOtherLanguages = $entity->getKeyInOtherLanguages($this->getCleanKey(), $this->languageId);
// If we have only one language, the different check must be turned off.
if( ! isset($routesInOtherLanguages) || empty($routesInOtherLanguages) )
{
// Get rid of the different check
$validation['rules'] = str_replace('|different:[[routesInOtherLanguages]]', '' , $validation['rules']);
}
else
{
// Replace [[routesInOtherLanguages]] with the actual value
$validation['rules'] = str_replace('[[routesInOtherLanguages]]', $routesInOtherLanguages , $validation['rules']);
}
return $validation;
}
public function render()
{
$this->parseStructure();
return View::make('kms::attributes.route', [
'attribute' => $this
]);
}
public function parseStructure()
{
$this->structure = str_replace('[[languageSlug]]', $this->getLanguageSlug($this->languageId), $this->structure);
$this->structure = str_replace('[[parentSlugs]]', 'parent/parent', $this->structure);
$this->structure = str_replace('[[slug]]', $this->slugField, $this->structure);
}
protected function getLanguageSlug($languageId)
{
if($languageId != null) return Language::find($languageId)->iso_2;
return '';
}
}