Created
May 7, 2014 17:17
-
-
Save dongilbert/6e8e0e0beaa5f127a4a8 to your computer and use it in GitHub Desktop.
System plugin to modify form inputs.
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 | |
/** | |
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | |
* @license GNU General Public License version 2 or later; see LICENSE.txt | |
*/ | |
defined('JPATH_BASE') or die; | |
class plgSystemFormmod extends JPlugin | |
{ | |
/** | |
* @param JForm $form The form to be altered. | |
* @param array $data The associated data for the form. | |
* | |
* @return boolean | |
* @since 1.6 | |
*/ | |
public function onContentPrepareForm($form, $data) | |
{ | |
if (!($form instanceof JForm)) | |
{ | |
$this->_subject->setError('JERROR_NOT_A_FORM'); | |
return false; | |
} | |
// Check we are manipulating a valid form. | |
if ($form->getName() !== 'com_mycomponent.site') | |
{ | |
return true; | |
} | |
// Add the show_attractions field | |
$type_field = new SimpleXMLElement('<field />'); | |
$type_field->addAttribute('type', 'radio'); | |
$type_field->addAttribute('name', 'show_attractions'); | |
$type_field->addAttribute('label', 'Allow Editing Attractions'); | |
$type_field->addAttribute('fieldset', 'advanced'); | |
$type_field->addAttribute('default', '1'); | |
$options = ['1' => 'Yes', '0' => 'No']; | |
foreach ($options as $key => $value) | |
{ | |
$child = $type_field->addChild('option', $value); | |
$child->addAttribute('value', $key); | |
} | |
$form->setField($type_field, 'params'); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment