Problem

The social_core_path_validate function can cause an event to be inaccessible.

The function checks for form_validate errors before adding a leading slash to the value of an alias field. However it appears that the address field is validated after the path field which causes the form to be rerendered but a leading slash is now added to an alias.

How to reproduce

On a vanilla Open Social installation.

  • Create a new event
  • Fill in the required fields
  • Be sure to leave the alias field empty
  • Fill in the following for an address
    • Country: United States
    • Addres: Bad Address
    • City: No City
    • State: California
    • Postcode: q
  • Save the form
  • See the form error for the postalcode
  • Correct the postalcode (94925 works)
  • Notice that the alias field is now set to "/"
  • Save the event

You will now be redirected to the homepage and manually entering the node's address will also lead to the homepage. This is because "/" is a valid alias. Manually going to the /node//edit page and saving the node fixes the issue because the alias alter function in social_core does an ltrim on the default value which removes the single "/".

Proposed resolution

In the social_core_path_validate function, don't care about any form errors except the one set by the validation function itself.

In the alter function for the form element, also provide an ltrim on any value that may be set. This causes the '/' to be added in the validator and then removed in the alter function before being rendered.

Comments

Kingdutch created an issue. See original summary.

kingdutch’s picture

Status: Active » Needs review
StatusFileSize
new2.35 KB

Pull request created here: https://github.com/goalgorilla/open_social/pull/921

The solution is slightly different from what's mentioned in the issue summary because the field_widget_form_alter hook is not called after the form validation as the form is cached by Drupal.

The changes made preserve the current behaviour while fixing the problem.

jaapjan’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.