-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New event so more validation classes can be added on the fly #1490
Conversation
I ran into a situation where I needed more complex validation rules like min and max length for strings and min and max values for integers. Without this change, I cannot make it.
WHat are your thoughts @kiatng @colinmollenhour @sreichel ? |
Is it for product or customer? Can you provide an example? |
This event can be used for any EAV attribute, but I'm using it for stricter product data entry. My customer has a huge database and wants extreme strictness on all data entry. One generic sample I can give it this, but I'd doing way more...
|
I see, the class names are intended for For me, it was for customer attributes, updated with a simple script: 'tdn' => [
'frontend_label' => ['Passport'],
'used_in_forms' => ['adminhtml_customer', 'customer_account_edit', 'ap_employee', 'ap_dependent'],
'apply_to' => [$groupIds['Member'], $groupIds['Dependent']],
'frontend_class' => 'validate-length maximum-length-9 minimum-length-4',
'sort_order' => 40
], |
Putting this in the DB is what I used to do, but it fails when you open an attribute and save it in Magento Admin. |
is it ok if I move the target to the 20.0 Branch? |
Yes sure. About v20, is this stable or... I haven't checked it out yet. |
ok, then I will change it later. v20 is similar stable, mostly because it does not contain much additional changes currently https://github.com/OpenMage/magento-lts/blob/20.0/.github/changelog/version_20.txt |
Sorry, my earlier comment is adding new customer attributes, only addressing part of the issue. It has been more than 5 years, and I forgot about the other part, resetting of the /* fix resetting of frontend_class field */
$frontendInputElm = $form->getElement('frontend_class');
$additionalTypes = array(
array(
'value' => 'validate-upper-alphanum',
'label' => Mage::helper('extendedcustomer')->__('Letters (A-Z) or Numbers (0-9)')
),
array(
'value' => 'validate-no-future-date',
'label' => Mage::helper('extendedcustomer')->__('No future date')
),
array(
'value' => 'validate-length maximum-length-9 minimum-length-4',
'label' => Mage::helper('extendedcustomer')->__('Validate passport #')
),
// ... more types
);
/** @see Varien_Data_Form_Element_Select */
$frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes);
$frontendInputElm->setValues($frontendInputValues); The above is an override, but perhaps a better solution is adding the BTW, there is also a resetting of |
Revisiting our old code again, and I found this: magento-lts/app/code/core/Mage/Eav/Helper/Data.php Lines 80 to 110 in 08d41c2
Lines 95-96: $_entityTypeClasses = Mage::app()->getConfig()
->getNode('global/eav_frontendclasses/' . $entityTypeCode); That's just what this is:
I just saw that, I'll try it to see if it works. |
I am happy to report that the following works for me: <!-- in your custom module /etc/config.xml -->
<global>
<!-- ... -->
<eav_frontendclasses>
<customer>
<passport>
<value>validate-length maximum-length-9 minimum-length-4</value>
<label>Validate passport #</label>
</passport>
<abc>
<value>abc</value>
<label>Validate ABC</label>
</abc>
</customer>
</eav_frontendclasses>
</global> For
@woutersamaey Please try to see if this works for you. If it does, it provides configurable |
I'm still not seeing why the "Input Validation for Store Owner" plus config.xml solution that @kiatng pointed out doesn't solve it.. I suppose you want the user to be able to enter any arbitrary length at any time? But surely there are only so many possible lengths you could need to use and these could be added to the config.xml ahead of time. Anyway, no objection to adding another event, that is quite harmless. |
Ahhh... I see that the value of Max Length can be any integer input by a backend user, which cannot be pre-determined, and in which the validation rule is dependent on. It makes sense to me now. Instead of a targeted event for the function magento-lts/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Abstract.php Lines 45 to 55 in 7526749
public function setAttribute($attribute)
{
Mage::dispatchEvent('eav_entity_attribute_frontend_set_attribute', ['attribute' => $attribute]);
$this->_attribute = $attribute;
return $this;
} This allows other customization of the attribute's frontend properties. @woutersamaey 's observer can be: /** @var Mage_Eav_Model_Entity_Attribute $attribute */
$attribute = $observer->getAttribute();
$classes = [$attribute->getFrontendClass()];
$backend = $attribute->getBackendType();
if ($backend === 'varchar') {
$classes[] = 'validate-length';
$classes[] = 'maximum-length-255';
}
$attribute->setFrontendClass($classes); Is that OK? Can you test to see if it works for you? |
I switched the branch to 20.0 as said before in the thread. @woutersamaey what would you answer to last @kiatng comment? It would be nice (after all this work) to merge this PR :-) |
Why to change array to ArrayObject? However ... for ArrayObject |
I would put such PRs in the Draft, especially since there is also a conflict to be resolved, and if there is no feedback from the author within a reasonable time, it should be closed by mutual agreement. From what I can tell, the author is following a particular situation and he found a solution, but the changes can be implemented in a different way. |
to make it manipulable via the observer I guess |
|
but its a new Feature, so its better in V20
why does using |
All new features have been added to v19 .... we already addes some new events to v19. Why to change it now? (i`d reverted it to simple array ... makes no differences for observer and have less changes) |
it happened because people ignored the "no new features into v19" |
Who said that? We added new features before v20 was created ... v20 was only for breaking changes??? |
Did you read @kiatng suggestion? |
Will you update README too? |
This shouldn’t have been merged. |
It was useful, adding a new event is not very invasive, it had 3 approves(before fixing codestyle issues) and no change request. |
You switched the branch, made a modification and we were waiting on some feedbad. It shouldn’t have been merged! |
... |
I requested the change of the branch, the branch change was approved by to submitter, and technically @fballiano changed the branch. It was set to draft because of the merge conflict, which was resolved (and very straightforward) And again, none of you did a formell change request blocking the merge. |
Because we don’t block other people’s work with change request like you do but ask questions instead. The questions came after colin’s review and you know it. |
And i switched the branch 7 months ago! Before Sven started this huge work we all see every day which also unifies the branches a bit to avoid the constant conflicts. |
And this worked very well. I cant remember any merged PR having open questions or suggestions ... |
exactly, without frictions |
so here we are getting personal, having frictions and not talking anymore about the PR content. please move the other stuff into an own place, else I have to Lock here. |
you behave like this is your own property. |
Nailed it. |
what are you talking about? we think the merge was a mistake, it's not getting personal. 3 maintainers didn't like this PR 100% and asked for modification and you (after months we didn't see you here) come, merge it enforcing it (since when you change a line you invalidated all reviews) and threaten to lock the discussion. this is not ok. |
https://github.com/OpenMage/magento-lts/blob/1.9.4.x/app/Mage.php#L503-L509 arrays are copy-on-write, without being explicitly passed by reference |
Maybe you got me wrong? You are right, it has to be passed by reference. This works too ...
|
huh, Iam surprised this works for parts of array, but having only a part of an array being a reference looks like a mean and easy to overlook pitfall for people who continue to pass these to other functions, while an arrayObject is very clear for this and making it more transparent. <?php
function test ($data) {
$data['classes'][] = "yes";
}
$out = ["does it?"];
$array = [
"classes" => &$out,
"attribute" => [ "value"=>"other"]
];
test($array);
var_dump($array);
|
No downsides. Only unnecessary changes. Btw ... it also used in core ...
|
Description (*)
I ran into a situation where I needed more complex validation rules like min and max length for strings and min and max values for integers. Without this change, I cannot make it.
Contribution checklist (*)