{"action":"created","issue":{"url":"https://api.github.com/repos/joomla/joomla-cms/issues/3143","labels_url":"https://api.github.com/repos/joomla/joomla-cms/issues/3143/labels{/name}","comments_url":"https://api.github.com/repos/joomla/joomla-cms/issues/3143/comments","events_url":"https://api.github.com/repos/joomla/joomla-cms/issues/3143/events","html_url":"https://github.com/joomla/joomla-cms/pull/3143","id":27876406,"number":3143,"title":"fix JForm::setFieldAttribute()","user":{"login":"itbra","id":2728569,"avatar_url":"https://avatars.githubusercontent.com/u/2728569?v=3","gravatar_id":"","url":"https://api.github.com/users/itbra","html_url":"https://github.com/itbra","followers_url":"https://api.github.com/users/itbra/followers","following_url":"https://api.github.com/users/itbra/following{/other_user}","gists_url":"https://api.github.com/users/itbra/gists{/gist_id}","starred_url":"https://api.github.com/users/itbra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itbra/subscriptions","organizations_url":"https://api.github.com/users/itbra/orgs","repos_url":"https://api.github.com/users/itbra/repos","events_url":"https://api.github.com/users/itbra/events{/privacy}","received_events_url":"https://api.github.com/users/itbra/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/joomla/joomla-cms/labels/New%20Feature","name":"New Feature","color":"e102d8"},{"url":"https://api.github.com/repos/joomla/joomla-cms/labels/PR-staging","name":"PR-staging","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-02-19T14:00:09Z","updated_at":"2015-03-14T15:04:56Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/joomla/joomla-cms/pulls/3143","html_url":"https://github.com/joomla/joomla-cms/pull/3143","diff_url":"https://github.com/joomla/joomla-cms/pull/3143.diff","patch_url":"https://github.com/joomla/joomla-cms/pull/3143.patch"},"body":"Fixing issue described in [bug #31493](http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8103&tracker_item_id=31493), related to JForm (libraries/joomla/form/form.php)\r\n\r\nPresently JForm::setFieldAttributes sets passed attribute values without taking care for existing ones which may lead to loss. To prevent this and add new attribute values preserving existing ones one had to call:\r\n```\r\n$form->setFieldAttribute(\r\n   'fieldname',\r\n   'attribute',\r\n   $form->getFieldAttribute('fieldname', 'attribute', '', 'group') . ' newAttr1 newAttr2 newAttr3 ...',\r\n   'group'\r\n);\r\n```\r\nThis is not very comfortable and might lead to very long statements. Also, it does not take care for value duplication. The PR adds an additional function parameter as flag for merging or replacing (default) along with an extended processing statement. Adding attribute value statements will then look like:\r\n```\r\n$form->setFieldAttribute(\r\n   'fieldname',\r\n   'attribute',\r\n   'newAttr1 newAttr2 newAttr3 ...',   // a space separeted attributes list\r\n   'group',\r\n   false   // flag indicating whether to merge or replace\r\n);\r\n```\r\nWhen the last paramter is passed and set to 'false' the form first reads all values of the related form fields attribute, dumps them into an array, merges the passed attribute values and finally filters for duplicates. This way all attribute values are set without having dupes."},"comment":{"url":"https://api.github.com/repos/joomla/joomla-cms/issues/comments/80525420","html_url":"https://github.com/joomla/joomla-cms/pull/3143#issuecomment-80525420","issue_url":"https://api.github.com/repos/joomla/joomla-cms/issues/3143","id":80525420,"user":{"login":"itbra","id":2728569,"avatar_url":"https://avatars.githubusercontent.com/u/2728569?v=3","gravatar_id":"","url":"https://api.github.com/users/itbra","html_url":"https://github.com/itbra","followers_url":"https://api.github.com/users/itbra/followers","following_url":"https://api.github.com/users/itbra/following{/other_user}","gists_url":"https://api.github.com/users/itbra/gists{/gist_id}","starred_url":"https://api.github.com/users/itbra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itbra/subscriptions","organizations_url":"https://api.github.com/users/itbra/orgs","repos_url":"https://api.github.com/users/itbra/repos","events_url":"https://api.github.com/users/itbra/events{/privacy}","received_events_url":"https://api.github.com/users/itbra/received_events","type":"User","site_admin":false},"created_at":"2015-03-14T15:04:56Z","updated_at":"2015-03-14T15:04:56Z","body":"Somehow i don't get it. What do you mean with `expected behavior`? The main issue with this method - especially when it comes to ADD more values to an element's *class* attribute - is that it overrides existing values carelessly. The fix not only catches this issue but also checks for duplicates. The latter would potentially get created if you *append* new values to this attribute.\r\nTo prevent this duplication either there are two scenarios:\r\n\r\na) the developer must read the attribute first, prepare the value (remove any dupes) and then set the new value\r\nb) the field class method makes this job, which makes the developer's life easier\r\n\r\nI suppose you haven't had to add new class attributes to form fields on that often yet, have you?"}}