Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Call load_callback for every fields value in ModulePersonalData. #4018

Closed
wants to merge 3 commits into from

4 participants

@tristanlins

The ModulePersonalData calls the save_callback, but never the load_callback!

@Toflar

What about passing $this->User and $this too? Like for the save_callback :)

@tristanlins

I added the onsubmit_callback and passes $this->User and $this as @Toflar sugested.

@Toflar
Collaborator

Probably it was not really a good idea to pass $this->User. It's available anyway and the callbacks aren't consinstent in the FE and BE then.
@leofeyer thoughts? :-)

@leofeyer
Owner

I agree that the calls should be the same in FE and BE. Can you please check 06ac7f3 and 7616ecf (branch "personal-data-callbacks") and get back to me whether it works?

@leofeyer
Owner

@contao/workgroup-core Please check the changes so I can merge the feature branch.

@aschempp
Collaborator

I'm not sure why you're changing current behaviour? The save_callback is also passing the user. It should be very easy to distinguish TL_MOD in the callback, and $param->id will also be the same. We've also added $this at some point to have module information available.

One more thing I noticed, the variable should be called $varValue to follow Contao conventions.

@tristanlins

@aschempp But what about fields, that you fill with the load_callback? Thats how I find this problem, I tried to load a field value via the load_callback. Normally for these situations you need a save AND load callback, but only the save callback is triggered.
Thats just not the correct behaviour. Working with DCA records in FE editing should everytime call ALL callbacks, because you never can say which is needed in which situation.

@aschempp
Collaborator

I did not mean I don't want the callback. I want it like you implemented it, including the second (and third) parameters. Make the load_callback the same as the save_callback always was.

@tristanlins

@aschempp sry I missunderstand you -.-
I think @leofeyer allready do the right changes in the 7616ecf commit?!

@aschempp
Collaborator

He removed them! Thats the opposite of what I wanted. Please check the discussion from Yanick.

@leofeyer
Owner

If this feature is supposed to make it into Contao 3.0, I need a very soon agreement and a code check by the @contao/workgroup-core. Otherwise I'll have to reassign the ticket to Contao 3.1.

@aschempp
Collaborator

I've submitted my recommended changes in #4585

  1. Follow Contao variable name conventions ($varValue not $value)
  2. Include second and third parameter on callback. This is useful because in the callback, $dc->id will still work and return the user ID. It also follows the existing save_callback, and you doubt you want to change (and break) that.

Apart from these things, I'm very happy with the changes. I've also checked the core, there are no existing callbacks that would be broken.

@leofeyer
Owner

However, now the callbacks are inconsistent, because in the back end, they will pass $varValue and $dc and in the front end, they will pass $varValue, $this->User and $dc. This is not acceptable, so I will revert those changes.

@aschempp
Collaborator

That is not really true. First of all, the existing callbacks work the same, so it does make sense to keep it. Secondly, the idea was that $dc->id works the same in frontend and backend. It does now because $dc->id should return the user ID. The third parameter from the frontend is not a $dc, it's the module object. It allows to define custom settings into the module definition, and handle them inside the callback.

@leofeyer
Owner

Ok, granted you have a point. But my callback looks like this:

<?php

function callback($varValue, \DataContainer $dc)
{
}

This does not work with your callback, right?

@leofeyer
Owner

I have reverted my changes until we talked.

@leofeyer
Owner

Implemented in ce4faf2.

@leofeyer leofeyer closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2012
  1. Call load_callback for every fields value.

    Tristan Lins authored
  2. Call onsubmit_callback when profile is updated.

    Tristan Lins authored
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 2 deletions.
  1. +28 −2 system/modules/frontend/ModulePersonalData.php
View
30 system/modules/frontend/ModulePersonalData.php
@@ -143,7 +143,20 @@ protected function compile()
$arrData['eval']['tableless'] = $this->tableless;
$arrData['eval']['required'] = ($this->User->$field == '' && $arrData['eval']['mandatory']) ? true : false;
- $objWidget = new $strClass($this->prepareForWidget($arrData, $field, $this->User->$field));
+ $value = $this->User->$field;
+ if (isset($arrData['load_callback']) && is_array($arrData['load_callback']))
+ {
+ foreach ($arrData['load_callback'] as $callback)
+ {
+ if (is_array($callback))
+ {
+ $this->import($callback[0]);
+ $value = $this->$callback[0]->$callback[1]($value, $this->User, $this);
+ }
+ }
+ }
+
+ $objWidget = new $strClass($this->prepareForWidget($arrData, $field, $value));
$objWidget->storeValues = true;
$objWidget->rowClass = 'row_'.$row . (($row == 0) ? ' row_first' : '') . ((($row % 2) == 0) ? ' even' : ' odd');
@@ -259,7 +272,20 @@ protected function compile()
$this->$callback[0]->$callback[1]($this->User, $_SESSION['FORM_DATA'], $this);
}
}
-
+
+ // Call onsubmit_callback
+ if (is_array($GLOBALS['TL_DCA']['tl_member']['config']['onsubmit_callback']))
+ {
+ foreach ($GLOBALS['TL_DCA']['tl_member']['config']['onsubmit_callback'] as $callback)
+ {
+ if (is_array($callback))
+ {
+ $this->import($callback[0]);
+ $this->$callback[0]->$callback[1]($this->User, $this);
+ }
+ }
+ }
+
$this->jumpToOrReload($this->jumpTo);
}
Something went wrong with that request. Please try again.