Skip to content

Commit

Permalink
Adding onElementCanUse call to element canUse(method), and the hook f…
Browse files Browse the repository at this point in the history
…or it in form PHP plugin. Returning false will set an element to read only.
  • Loading branch information
cheesegrits committed Feb 4, 2017
1 parent aa7fe59 commit 07fd7bf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/com_fabrik/models/element.php
Expand Up @@ -1091,6 +1091,15 @@ public function canUse($location = 'form', $event = null)
}
}
}
else if ($this->access->use && $location == 'form')
{
$formModel = $this->getFormModel();
$pluginManager = FabrikWorker::getPluginManager();
if (in_array(false, $pluginManager->runPlugins('onElementCanUse', $formModel, 'form', $this)))
{
$this->access->use = false;
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions plugins/fabrik_form/php/forms/fields.xml
Expand Up @@ -28,6 +28,7 @@
<option value="onDeleteRowsForm">PLG_FORM_PHP_PROCESS_ONDELETEROWSFORM</option>
<option value="onAfterDeleteRowsForm">PLG_FORM_PHP_PROCESS_ONAFTERDELETEROWSFORM</option>
<option value="onSavePage">PLG_FORM_PHP_PROCESS_ONSAVEPAGE</option>
<option value="onElementCanUse">PLG_FORM_PHP_PROCESS_ONELEMENTCANUSE</option>
</field>

<field description="PLG_FORM_PHP_FILE_DESC" directory="plugins/fabrik_form/php/scripts/" hide_default="1" label="PLG_FORM_PHP_FILE_LABEL" name="form_php_file" repeat="true" type="filelist"/>
Expand Down
Expand Up @@ -28,3 +28,4 @@ PLG_FORM_PHP_PROCESS_GETENDCONTENT="After the end of the form (getEndContent)"
PLG_FORM_PHP_PROCESS_ONDELETEROWSFORM="On record deletion (onDeleteRowsForm)"
PLG_FORM_PHP_PROCESS_ONAFTERDELETEROWSFORM="After record deletion (onAfterDeleteRowsForm)"
PLG_FORM_PHP_PROCESS_ONSAVEPAGE="On saving a page in a multi-page form (onSavePage)"
PLG_FORM_PHP_PROCESS_ONELEMENTCANUSE="On canUse test for elements in form (onElementCanUse)"
32 changes: 32 additions & 0 deletions plugins/fabrik_form/php/php.php
Expand Up @@ -303,6 +303,38 @@ public function onBeforeLoad()
return true;
}

/**
* Run for each element's canUse. Return false to make an element read only
*
* @param array $args array containing element model being tested
*
* @return bool
*/
public function onElementCanUse($args)
{
$params = $this->getParams();

if ($params->get('only_process_curl') == 'onElementCanUse')
{
$formModel = $this->getModel();
$elementModel = FArrayHelper::getValue($args, 0, false);
if ($elementModel)
{
$w = new FabrikWorker;
$code = $w->parseMessageForPlaceHolder($params->get('curl_code', ''), $formModel->data, true, true);
$php_result = eval($code);

if ($php_result === false)
{
return false;
}
}
}

return true;
}


/**
* Run during form rendering, when all the form's JS is assembled and ready
* data found in $formModel->data
Expand Down

0 comments on commit 07fd7bf

Please sign in to comment.