2

Commerce Credits says that the credit name should

It is recommended that this name begin with a capital letter and contain only letters, number and spaces. This name must be unique.

I am generating a credit name from a profile2 name and a node title and working with the case "John's credit type'.

Clearly the escaped version 'John's credit type' contains characters other than a letter, number or space. So I am using the raw value and getting rid of the other characters. This seems like a relatively untested way of doing things and interferes with the users choice a lot. Is this the best implementation?

Just get rid of raw characters implementation

public function generatePassName($node) {
  $studio_profile = profile2_load_by_user($node->uid, YogaHiveStudioPass::STUDIO_PROFILE_TYPE);
  $studio_profile_name = field_get_items('profile2', $studio_profile, 'field_studio_name', 'value');
  $clean_name = preg_replace("/[^A-Za-z0-9 ]/", '', $studio_profile_name[0]['value']); 
  $pass_name = implode(' ', array(
    $clean_name,
    $node->title
));

  return $pass_name;
}

Implementation using Drupal escaping

public function generatePassName($node) {
  $studio_profile = profile2_load_by_user($node->uid, YogaHiveStudioPass::STUDIO_PROFILE_TYPE);
  $studio_profile_name = field_get_items('profile2', $studio_profile, 'field_studio_name', 'value');
  $studio_profile_markup = field_view_value('profile2', $studio_profile, 'field_studio_name', $studio_profile_name[0])
  $pass_name = implode(' ', array(
    $studio_profile_markup['#markup'],
    $node->title
));

  return $pass_name;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.