I have been struggling with this problem for a week now, please can someone help me. On the "submit an article" page which is only available for "registered users", can you disable or remove the field that allows the registered user to select an "access level"? I want it to be automatically set to "public" because normal registered users don't know what that means so will get confused by it
thanks
Write a content plugin and implement the function onContentPrepareForm like
public function onContentPrepareForm($form, $data) {
if (! in_array($form->getName(), array('com_content.article'))) {
return true;
}
$form->removeField('access');
return true;
}
and onContentBeforeSave
public function onContentBeforeSave($context, $article, $isNew) {
if ($context != 'com_content.article' && $context != 'com_content.form') {
return;
}
$article->access = 1;
return true;
}
Perhaps are some of the context names incorrect as I wrote to code out of my memory :-)
Related
In Magento 1.7, whenever I go through the checkout process as guest at the end of the onepage checkout process I get the Magento error:
Customer email is required
Having used xDebug to profile the problem the code I have in my observer which is executed on the sales_order_place_after observer I have a function called afterOrderPlaced()
public function afterOrderPlaced($observer)
{
$organisation_id = Mage::getSingleton('customer/session')->getOrganisationId(); #$organisation_id = 25679;
$this->_order = $observer->getEvent()->getOrder();
$this->_order->setOrganisationId($organisation_id)->save();
// Customer stuff
$this->_customer_id = $this->_order->getCustomerId();
$this->_customer = $this->_order->getCustomer();
// problem on the next line below #PROBLEM HERE#
$this->_customer->setOrganisationId($organisation_id)->save();
}
The issue is on the last line of the function - for some reason it doesn't seem to like the save() on the customer object. This goes into the core files in Mage\Core\Model\Resource\Transaction.php on line 161 within the save() - see below:
public function save()
{
$this->_startTransaction();
$error = false;
try {
foreach ($this->_objects as $object) {
$object->save();
}
} catch (Exception $e) {
$error = $e;
}
if ($error === false) {
try {
$this->_runCallbacks();
} catch (Exception $e) {
$error = $e; ## ERROR IS HAPPENING HERE?! ##
}
}
if ($error) {
$this->_rollbackTransaction();
throw $error;
} else {
$this->_commitTransaction();
}
return $this;
}
Can anyone indicate what my problem maybe within my observer and why it doesn't seem to like to save the custom organisation_id to the customer object?
For guest user why are you trying to save organisation id in customer profile, there will no customer profile to save because Magento doesn't create customer in customer entity for guest users. You need to add condition to your function above to resolve the problem
if(!$order->getCustomerIsGuest()){
// Customer stuff
$this->_customer_id = $this->_order->getCustomerId();
$this->_customer = $this->_order->getCustomer();
// problem on the next line below #PROBLEM HERE#
$this->_customer->setOrganisationId($organisation_id)->save();
}
Hope the above helps
Cheers
S
working good in crm 2011 but not in crm 2013 online
On opportunity Entity create New record form i show only:
1.Some attributes(all other fields/Section/Tabs are hide on form)
2.and an Html button like
function OnFormLoad(){
if(Xrm.Page.ui.getFormType() == 1 ) {
SetRequiredLevelToNone();
createHtmlButton("Save");
HideTabsAndSections()
}
else {
}
}
On click of Html button following function is triggered.
function showWholeForm() {
Xrm.Page.data.entity.save();
}
I want to show all the fields of form after save, means want to reload whole form.
As working in crm 2011
The save method in CRM 2013 will not refresh the page anymore. The new refresh method should be used in this case, as follows:
Xrm.Page.data.refresh(save).then(successCallback, errorCallback);
save: Boolean value to be passed as true if data should be saved
after it is refreshed.
successCallback: Function to call when the operation succeeds
errorCallbak: Function to call when the operation fails, that will be passed an object with 2 properties - error code (number) and localized error message (string)
You could find the method documented here: http://msdn.microsoft.com/en-us/library/dn481607(v=crm.6).aspx
I think you should first disable the auto-save if you want consistency with CRM 2011.
function OnSaveDisableAutoSave(eventArgs) {
var saveType = eventArgs.getEventArgs().getSaveMode();
if (saveType == 70 ||saveType == 2)
{ //Disable AutoSave
eventArgs.preventDefault();
}
}
and then
function showWholeForm() {
Xrm.Page.data.refresh(true).then(successCallback, errorCallback);
}
To fix this you can do:
var saved = false;
function onLoad(){
checkIfFormShouldBeReadOnly();
attachEvent();
}
function attachEvent() {
Xrm.Page.data.entity.addOnSave(executeOnSave);
}
function executeOnSave(saveExecution) {
if (!saved) {
saved = true;
Xrm.Page.data.save().then(
function () {
checkIfFormShouldBeReadOnly();
},
function (errorCode, message) {
Xrm.Page.data.refresh();
}
);
}
}
I am trying to make the ajax request more user friendly. It is a scenario that using a token which can be reuse in a period of time. However in time that a user has inactive for a certain time and tried to use the form, user will observe that the ajax not working but donno why. What I'm gonna do here is to display the message.
Using my testing code, doing return new CakeResponse seems to be return true in blackhole and therefore the $result is true although the User edit should not be triggered
public function beforeFilter() {
$this->Security->blackHoleCallback = 'blackhole';
}
public function blackhole($type) {
if ($this->request->is('ajax')) {
$this->log('blackhole here','debug');
return new CakeResponse(array('body'=> json_encode(array('data'=>'The request has been blackholed')),'status'=>500));
}else{
$this->log('blackhole there','debug');
return new CakeResponse(array('body'=> json_encode(array('data'=>'The request has been blackholed')),'status'=>500));
}
}
in the userapp
public function edit() {
$userId=$this->Auth->user('id');
if (empty($this->request->data)) {
$this->request->data = $this->User->read(null, $userId);
}
if ($this->request->is('ajax')) {
if($result = $this->{$this->modelClass}->edit($userId, $this->request->data)){
$this->Session->write('Auth', $this->User->read(null, $userId));
return new CakeResponse(array('body'=> json_encode(array('data'=>'saved')),'status'=>200));
}else{
return new CakeResponse(array('body'=> json_encode(array('data'=>'error')),'status'=>500));
}
}
}
Progress 1:
Unsolved, perhaps needed to use event handler or exception, though it will be somehow complicated . Still thinking while refining other plugin feature.
I am getting a System.NullReferenceException: Object reference not set to an instance of an object when ever I hit "back" on a wizard I am using (also, I am getting a "confirm resubmission" page if I just hit back on the browser). This is due to the following code (normally, without using this system hitting "back" on my wizard or the back button on the browser works fine):
// Loop through the items and make sure they are Selected if the value has been posted
if(Model != null)
{
foreach (var item in selectorModel.Items)
{
if (supportsMany)
{
var modelStateValue = GetModelStateValue<string[]>(Html, fieldName) ?? ((IEnumerable)Model).OfType<object>().Select(m => m.ToString());
item.Selected = modelStateValue.Contains(item.Value);
}
else
{
var modelStateValue = GetModelStateValue<string>(Html, fieldName);
item.Selected = modelStateValue.Equals(item.Value, StringComparison.OrdinalIgnoreCase);
}
}
}
the error happens on item.Selected = modelStateValue.Equals(item.Value, StringComparison.OrdinalIgnoreCase);
The wizard code for the "back" button on the wizard looks like this in the controller:
public ActionResult EMailQuoteConfirm(string backButton, string nextButton)
{
if (backButton != null)
return RedirectToAction("EMailQuoteBasicDetails");
else if (nextButton != null)
return RedirectToAction("EMailQuoteSubmitted");
else
return View("EMailQuote/Confirm", myData);
}
Any advice is appreciated.
After much research into the issue I determined it was serialization that was causing this weird error. And although serialization worked well, I've opted for a jQuery solution which works better with this code.
Lesson learned: jQuery ain't so bad. :)
I'm creating a component in Joomla! 1.7 and I'd like to take advantage of the framework's check-out/check-in features. Currently
How do I mark a component record as "checked out" when a user requests the edit task for that record?
How do I mark a record as "checked in" when the user attempts to store his or her edits?
How do I test the checked-in/checked-out status of a component's record at edit time?
Thanks!
Basicly you need two methods in your model, which you can call whenever you want to:
function checkin()
{
if ($this->_id)
{
$item= & $this->getTable();
if(! $item->checkin($this->_id)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
}
return false;
}
function checkout($uid = null)
{
if ($this->_id)
{
// Make sure we have a user id to checkout the article with
if (is_null($uid)) {
$user =& JFactory::getUser();
$uid = $user->get('id');
}
// Lets get to it and checkout the thing...
$item= & $this->getTable();
if(!$item->checkout($uid, $this->_id)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return true;
}
return false;
}
To mark item as checked, first of all you have to have column called checked_out with default value 0, also you need checked_out_time to store time, when item was checked out.
Hope it helps.