Last active
December 14, 2015 07:19
-
-
Save notbrain/5050157 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class featureButtonSlotActions extends BaseaButtonSlotActions { | |
/** | |
* Image association is handled by a separate action | |
* @param sfRequest $request | |
* @return mixed | |
*/ | |
public function executeImage(sfRequest $request) | |
{ | |
if ($request->getParameter('aMediaCancel')) | |
{ | |
return $this->redirectToPage(); | |
} | |
$this->logMessage("====== in featureButtonSlotActions::executeImage", "info"); | |
$this->editSetup(); | |
$item = Doctrine::getTable('aMediaItem')->find($request->getParameter('aMediaId')); | |
$this->slot->unlink('MediaItems'); | |
// It's not a bug to have no media item selected - allow the trashcan to work to remove it | |
if ($item && ($item->type === 'image')) | |
{ | |
$this->slot->link('MediaItems', array($item->id)); | |
} | |
return $this->editSave(); | |
} | |
/** | |
* Use the edit view for the URL (and any other well-behaved fields that may arise) | |
* @param sfRequest $request | |
* @return mixed | |
*/ | |
public function executeEdit(sfRequest $request) | |
{ | |
$this->logMessage("====== in featureButtonSlotActions::executeEdit", "info"); | |
$this->editSetup(); | |
// Work around FCK's incompatibility with AJAX and bracketed field names | |
// (it insists on making the ID bracketed too which won't work for AJAX) | |
// Don't forget, there's a CSRF field out there too. We need to grep through | |
// the submitted fields and get all of the relevant ones, reinventing what | |
// PHP's bracket syntax would do for us if FCK were compatible with it | |
$values = $request->getParameterHolder()->getAll(); | |
$value = array(); | |
foreach ($values as $k => $v) | |
{ | |
if (preg_match('/^slot-form-' . $this->id . '-(.*)$/', $k, $matches)) | |
{ | |
$value[$matches[1]] = $v; | |
} | |
} | |
if ($this->getOption('editLink', null) !== false) | |
{ | |
// Trim whitespace off the front & end of the URL to avoid failing validation on a perfectly acceptable URL | |
$value['url'] = trim($value['url']); | |
} | |
$this->form = new featureButtonSlotEditForm($this->id, $this->options); | |
$this->form->bind($value); | |
if ($this->form->isValid()) | |
{ | |
if ($this->getOption('editLink', null) !== false) | |
{ | |
$url = $this->form->getValue('url'); | |
} | |
$value = $this->slot->getArrayValue(); | |
if ($this->getOption('editLink', null) !== false) | |
{ | |
$value['url'] = $url; | |
} | |
$value['title'] = $this->form->getValue('title'); | |
$value['description'] = $this->form->getValue('description'); | |
$this->slot->setArrayValue($value); | |
$result = $this->editSave(); | |
return $result; | |
} | |
else | |
{ | |
// Makes $this->form available to the next iteration of the | |
// edit view so that validation errors can be seen | |
return $this->editRetry(); | |
} | |
} | |
} | |
This file contains hidden or 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 | |
class featureButtonSlotComponents extends BaseaButtonSlotComponents { | |
protected function getButtonMedia() | |
{ | |
// We are going to return the media in both Normal and Edit View | |
// Backwards compatibility with pkContextCMS button slots that the data migration task missed | |
if (!count($this->slot->MediaItems)) | |
{ | |
$value = $this->slot->getArrayValue(); | |
if (isset($value['image'])) | |
{ | |
$mediaItem = Doctrine::getTable('aMediaItem')->find($value['image']->id); | |
if ($mediaItem) | |
{ | |
$this->slot->MediaItems[] = $mediaItem; | |
} | |
} | |
} | |
if (!count($this->slot->MediaItems)) | |
{ | |
$this->item = false; | |
$this->itemId = false; | |
} | |
else | |
{ | |
$this->item = $this->slot->MediaItems[0]; | |
$this->itemId = $this->item->id; | |
$this->dimensions = aDimensions::constrain( | |
$this->item->width, | |
$this->item->height, | |
$this->item->format, | |
array("width" => $this->options['width'], | |
"height" => $this->options['flexHeight'] ? false : $this->options['height'], | |
"resizeType" => $this->options['resizeType'])); | |
if (($this->options['maxHeight'] !== false) && ($this->dimensions['height'] > $this->options['maxHeight'])) | |
{ | |
$this->dimensions = aDimensions::constrain( | |
$this->item->width, | |
$this->item->height, | |
$this->item->format, | |
array("width" => false, | |
"height" => $this->options['maxHeight'], | |
"resizeType" => $this->options['resizeType'])); | |
} | |
$this->embed = $this->item->getEmbedCode($this->dimensions['width'], $this->dimensions['height'], $this->dimensions['resizeType'], $this->dimensions['format'], false, 'opaque', false, array('alt' => strlen($this->options['title']) ? $this->options['title'] : '')); | |
} | |
} | |
/** | |
* DOCUMENT ME | |
*/ | |
protected function setupOptions() | |
{ | |
$this->options['constraints'] = $this->getOption('constraints', array()); | |
$this->options['width'] = $this->getOption('width', 440); | |
$this->options['height'] = $this->getOption('height', false); | |
$this->options['resizeType'] = $this->getOption('resizeType', 's'); | |
$this->options['flexHeight'] = $this->getOption('flexHeight', true); | |
$this->options['maxHeight'] = $this->getOption('maxHeight', false); | |
$this->options['title'] = $this->getOption('title', false); | |
$this->options['description'] = $this->getOption('description', true); | |
$this->options['link'] = $this->getOption('link', false); | |
$this->options['url'] = $this->getOption('link', false); | |
$this->options['rollover'] = $this->getOption('rollover', true); | |
$this->options['defaultImage'] = $this->getOption('defaultImage', false); | |
$this->options['itemTemplate'] = $this->getOption('itemTemplate', 'default'); | |
$this->options['image'] = $this->getOption('image', true); | |
} | |
/** | |
* DOCUMENT ME | |
*/ | |
public function executeEditView() | |
{ | |
$this->setup(); | |
$this->setupOptions(); | |
$this->options['width'] = 160; | |
$this->options['height'] = 160; | |
// Careful, don't clobber a form object provided to us with validation errors | |
// from an earlier pass | |
if (!isset($this->form)) | |
{ | |
// $this->logMessage("HERE --- ID = " . $this->id, "info"); | |
$this->form = new featureButtonSlotEditForm($this->id, $this->options); | |
$value = $this->slot->getArrayValue(); | |
if (isset($value['url'])) | |
{ | |
$this->form->setDefault('url', $value['url']); | |
} | |
else | |
{ | |
$this->form->setDefault('url', $this->getOption('link')); | |
} | |
if (isset($value['title'])) | |
{ | |
$this->form->setDefault('title', $value['title']); | |
} | |
else | |
{ | |
// Careful, just plain true is a valid setting for this option | |
$title = $this->getOption('title'); | |
if (strlen($title) && ($title !== true)) | |
{ | |
$this->form->setDefault('title', $title); | |
} | |
} | |
if (isset($value['description'])) | |
{ | |
$this->form->setDefault('description', $value['description']); | |
} | |
} | |
$this->getButtonMedia(); | |
} | |
/** | |
* DOCUMENT ME | |
*/ | |
public function executeNormalView() | |
{ | |
// Mostly identical to aImage, but we have the URL to contend with too | |
$this->setup(); | |
$this->setupOptions(); | |
// Behave well if it's not set yet! | |
$data = $this->slot->getArrayValue(); | |
// If there is a URL stored in the slot | |
// Use that URL (instead of the supplied link slot) | |
if (isset($data['url'])) | |
{ | |
$this->options['url'] = $data['url']; | |
} | |
// If the title is TRUE or a String, check if there's a title set in the slot $data | |
// IF NOT, THEN check if there's a string set in the slot options | |
if ($this->options['title']) | |
{ | |
if (isset($data['title'])) | |
{ | |
$this->options['title'] = $data['title']; | |
} | |
else | |
{ | |
$this->options['title'] = ($this->options['title'] === true) ? false : $this->options['title']; | |
} | |
} | |
if ($this->options['description']) | |
{ | |
if (isset($data['description'])) { | |
$this->options['description'] = $data['description']; | |
} | |
else | |
{ | |
$this->options['description'] = false; | |
} | |
} | |
$this->getButtonMedia(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment