webCOMAND

cObject::edit_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 editing variants, nor will it ensure that the variant is unique within this content object; both are verified during validation.

Prototype

void edit_variant(cObject|array $dimensions = NULL)

Parameters

  • dimensions - The dimension or array of dimensions to apply to the variant.  If none are specified, the variant dimensions will not be modified.

Example

$repo = comand::repo();

// get French and Spanish Language Dimensions
$fr = $repo->get_first("FROM Language WHERE Title='French'");
$es = $repo->get_first("FROM Language WHERE Title='Spanish'");

// get the French variant of an Article
$article = $repo->get_first("FROM Article WHERE Title='Article Title'");
$article_fr = $article->get_variant($fr);
if($article_fr) {
    // change the French variant to a Spanish variant
    $article_fr->edit_variant($es);
    $article_fr->Title = 'Título del artículo';
    $article_fr->approve();
}

Related

add_variant(), can_edit_variant()