webCOMAND

cObject::add_variant()

Creates a new variant for the content object this model represents.  The new variant's initial values will be based on the values of this model, with the exception of the dimensions passed here as an option.

This function will not check authorizations for adding variants, nor will it ensure that the new variant is unique within this content object; both are verified during validation.

Prototype

cObject add_variant(cObject|array $dimensions = NULL)

Parameters

  • dimensions - The dimension or array of dimensions to apply to the new variant.  If none are specified, the new variant will have the same dimensions as the one it is copied from.

Return

The cObject representing the new variant.

Example

$repo = comand::repo();

// get Spanish Language Dimension
$es = $repo->get_first("FROM Language WHERE Title='Spanish'");

// get the Spanish variant of an Article, if it exists
$article = $repo->get_first("FROM Article WHERE Title='Article Title'");
$article_es = $article->get_variant($es);
if(!$article_es) {
    // if a Spanish variant doesn't exist, add one
    $article_es = $article->add_variant($es);
}
// update the approved Spanish variant title
$article_es->Title = 'Título del artículo';
$article_es->approve();

Related

edit_variant(), can_add_variant()