Create a non-existent attribute, or update an existing attribute

@param Organization $organization
@param Attribute $attribute
@return bool|null
351019
public function addOrUpdateAttribute(Organization $organization, $attribute)
    {
        $url = self::makeAttributeUrl($organization->id, null, $attribute->name);
        $data = json_encode($attribute);
        $response = $this->service->prepAndSend($url, array(201, 200), 'PUT', $data, true);

        return Attribute::createFromJSON(json_decode($response));
    }
1336848
public static function setOrganization($organization, $basepath = '/')
    {
        if ($organization) {
            // Set the cookie for 30 days
            return self::set(self::ORGANIZATION_COOKIE, $organization, 30, $basepath);
        }
    }
487766
public function addAttribute(Attribute $attribute): ComplexEntity
	{
		$this->attributesCollection = $this->getAttributes()->addAttribute($attribute);
		return $this;
	}
328980
protected function createAttributeTranslation($name, $locale, Attribute $attribute)
    {
        $translation = new AttributeTranslation();
        $translation->setName($name);
        $translation->setLocale($locale);
        $translation->setAttribute($attribute);

        $attribute->addTranslation($translation);

        return $translation;
    }
1001357
public function create($data, $organizationId = null)
    {
        if (isset($organizationId)) {
            return $this->client()->put($data, 'organizations/{organizationId}', ['organizationId' => $organizationId]);
        }

        return $this->client()->post($data, 'organizations');
    }
280612
static OrganizationSettings updateOrganizationSettings(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
      // Start setting up a request to update OrganizationSettings for.
      // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
      OrganizationSettings organizationSettings =
          OrganizationSettings.newBuilder()
              .setName(organizationName.toString() + "/organizationSettings")
              .setEnableAssetDiscovery(true)
              .build();
      FieldMask updateMask = FieldMask.newBuilder().addPaths("enable_asset_discovery").build();

      UpdateOrganizationSettingsRequest.Builder request =
          UpdateOrganizationSettingsRequest.newBuilder()
              .setOrganizationSettings(organizationSettings)
              .setUpdateMask(updateMask);

      // Call the API.
      OrganizationSettings response = client.updateOrganizationSettings(request.build());

      System.out.println("Organization Settings have been updated:");
      System.out.println(response);
      return response;
    } catch (IOException e) {
      throw new RuntimeException("Couldn't create client.", e);
    }
  }
1112607
protected function getRelationClosure(Entity $entity, Attribute $attribute)
    {
        $method = $attribute->is_collection ? 'hasMany' : 'hasOne';

        // This will return a closure fully binded to the current entity instance,
        // which will help us to simulate any relation as if it was made in the
        // original entity class definition using a function statement.
        return Closure::bind(function () use ($entity, $attribute, $method) {
            $relation = $entity->$method($attribute->getAttribute('type'), 'entity_id', 'id');

            // Since an attribute could be attached to multiple entities, then values could have
            // same entity ID, but for different entity types, so we need to add type where
            // clause to fetch only values related to the given entity ID + entity type.
            $relation->where('entity_type', get_class($entity));

            // We add a where clause in order to fetch only the elements that are
            // related to the given attribute. If no condition is set, it will
            // fetch all the value rows related to the current entity.
            return $relation->where($attribute->getForeignKey(), $attribute->getKey());
        }, $entity, get_class($entity));
    }
385126
public function setDOMElementAttribute(DOMElement $element, $attribute, $value)
    {
        XmlUtils::setDOMElementAttribute($element, $this->getAttributeName($element, $attribute), $value);
    }
629378
public function authorized($entity, $attribute, $operation)
    {
        $authorized = true;
        $classname = get_class($entity);
        if (!array_key_exists($classname, $this->rights)) {
            $this->buildRights($classname);
        }

        $attribute = str_replace('/', '', $attribute);
        if (true === $authorized && !array_key_exists($attribute, $this->rights[$classname])) {
            $authorized = false;
        }

        if (true === $authorized && !in_array($operation, $this->rights[$classname][$attribute])) {
            $authorized = false;
        }

        return $authorized;
    }
1186342
public function addAttribute(Attribute $attribute)
    {
        $name = $attribute->getName();

        if (isset($this->attributes[$name])) {
            throw new \LogicException(sprintf('Attribute "%s" already defined.', $name));
        }

        $this->attributes[$name] = $attribute;
    }
1135631
public function update(Attribute $attribute, array $data)
    {
        if (Session::has('multi_language_enabled')) {
            $languageId = $data['language_id'];
            $languaModel = Language::find($languageId);
            
            if ($languaModel->is_default) {
                return $attribute->update($data);
            } else {
                
                $translatedModel = $attribute
                    ->translations()
                    ->whereLanguageId($languageId)
                    ->first();
                if (null === $translatedModel) {
                    return AttributeTranslation::create(
                        array_merge($data, ['attribute_id' => $attribute->id])
                    );
                } else {
                    $translatedModel->update(
                        $data,
                        $attribute->getTranslatedAttributes()
                    );

                    return $translatedModel;
                }
            }
        } else {
            return $attribute->update($data);
        }
    }
718599
public void setAttributeEditable(Attribute attribute, boolean editable) {
		attribute.setEditable(editable);
		if (!(attribute instanceof LazyAttribute)) { // should not instantiate lazy attributes!
			if (attribute instanceof ManyToOneAttribute) {
				setAttributeEditable(((ManyToOneAttribute) attribute).getValue(), editable);
			} else if (attribute instanceof OneToManyAttribute) {
				List<AssociationValue> values = ((OneToManyAttribute) attribute).getValue();
				for (AssociationValue value : values) {
					setAttributeEditable(value, editable);
				}
			}
		}
	}
1041001
public function setPostAttribute($model, $attribute)
    {
        if ($attributeValue = Yii::$app->request->post($attribute, null)) {
            $model->setAttribute($attribute, $attributeValue);
        }
    }
1204090
protected function takeAttributeFromDOM($attribute)
    {
        switch ($attribute->localName) {
        case 'limit':
            $this->_limit = $attribute->nodeValue;
            break;
        default:
            parent::takeAttributeFromDOM($attribute);
        }
    }
146444
public function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        return $this->isOrganizationManager($token, $subject) ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED;
    }
901085
def organization_field_create(self, data, **kwargs):
        ""
        api_path = "/api/v2/organization_fields.json"
        return self.call(api_path, method="POST", data=data, **kwargs)
688306
protected function takeAttributeFromDOM($attribute)
    {
        switch ($attribute->localName) {
        case 'relationship':
            $this->_relationship = $attribute->nodeValue;
            break;
        case 'type':
            $this->_type = $attribute->nodeValue;
            break;
        default:
            parent::takeAttributeFromDOM($attribute);
        }
    }