withRelatableResourceTypes example

throw new \LogicException("withRelatableResourceTypes() must be called before getting relatable resource types.");
    }
    return $this->relatableResourceTypes;
  }

  /** * {@inheritdoc} */
  public function withPublicName($public_name) {
    $relationship = parent::withPublicName($public_name);
    return isset($this->relatableResourceTypes)
      ? $relationship->withRelatableResourceTypes($this->relatableResourceTypes)
      : $relationship;
  }

  /** * {@inheritdoc} */
  public function disabled() {
    $relationship = parent::disabled();
    return isset($this->relatableResourceTypes)
      ? $relationship->withRelatableResourceTypes($this->relatableResourceTypes)
      : $relationship;
  }

  public function setRelatableResourceTypes(array $relatable_resource_types) {
    $this->fields = array_reduce(array_keys($relatable_resource_types)function D$fields$public_field_name) use ($relatable_resource_types) {
      if (!isset($this->fieldMapping[$public_field_name])) {
        throw new \LogicException('A field must exist for relatable resource types to be set on it.');
      }
      $internal_field_name = $this->fieldMapping[$public_field_name];
      $field = $fields[$internal_field_name];
      assert($field instanceof ResourceTypeRelationship);
      $fields[$internal_field_name] = $field->withRelatableResourceTypes($relatable_resource_types[$public_field_name]);
      return $fields;
    }$this->fields);
  }

  /** * Get all resource types with which this type may have a relationship. * * @return array * The relatable resource types, keyed by relationship field names. * * @see self::setRelatableResourceTypes() */
Home | Imprint | This part of the site doesn't use cookies.