You are here

protected function CommerceFileLicenseEntity::_add_field_value in Commerce File 7

Add field value

Return value

TRUE if added

1 call to CommerceFileLicenseEntity::_add_field_value()
CommerceFileLicenseEntity::link_line_item in includes/commerce_file_license.entity.inc
Add a line item

File

includes/commerce_file_license.entity.inc, line 516
Provides a base class for CommerceFileLicenseEntity.

Class

CommerceFileLicenseEntity
A Commerce File License entity class.

Code

protected function _add_field_value($field_name, $new_item = NULL, $id_key = NULL) {

  // ensure field is initialized
  $this
    ->_init_field_value($field_name);

  // add new item if it doesn not exist already
  if (!empty($new_item)) {
    if (!empty($id_key)) {

      // exit if item exists
      $field_items = $this
        ->_get_field_value($field_name);
      if (!empty($field_items)) {
        foreach ($field_items as $delta => $item) {
          if (isset($item[$id_key]) && isset($new_item[$id_key]) && $item[$id_key] == $new_item[$id_key]) {
            return FALSE;
          }
        }
      }
    }

    // add it if we got here
    $langcode = field_language($this->entityType, $this, $field_name);
    if (empty($langcode)) {
      $langcode = LANGUAGE_NONE;
    }
    $this->{$field_name}[$langcode][] = $new_item;
  }
  return TRUE;
}