src/Service/NT8PropertyService.php
public function createAttributesFromTabs(array $attrib_data = []) {
    // Return value.
    $updatedAttrs = "";

    $save_status = FALSE;

    foreach ($attrib_data as $attr_key => $attribute) {

      $attr_array = [
        'field_attribute_code' => ['value' => $attribute->code],
        'field_attribute_brand' => ['value' => $attribute->brand],
        'field_attribute_labl' => ['value' => $attribute->label],
        'field_attribute_group' => ['value' => $attribute->group],
        'field_attribute_type' => ['value' => $attribute->type],
      ];

      // TODO: make this a configurable option or let the admin specify it.
      $attr_array['vid'] = $this::ATTRIBUTE_VOCAB_ID;
      // The name is needed by the Drupal Taxonomy API.
      $attr_array['name'] = $attribute->label;

      $term = Term::create($attr_array);

      // Modify terms of the same name if they already exist.
      $terms = self::loadTermsByNames($this::ATTRIBUTE_VOCAB_ID, [$attr_array['name']], function (&$term) use ($attr_array, &$save_status) {
        $term->get('field_attribute_code')->setValue($attr_array['field_attribute_code']);
        $term->get('field_attribute_brand')->setValue($attr_array['field_attribute_brand']);
        $term->get('field_attribute_labl')->setValue($attr_array['field_attribute_labl']);
        $term->get('field_attribute_group')->setValue($attr_array['field_attribute_group']);
        $term->get('field_attribute_type')->setValue($attr_array['field_attribute_type']);

        $save_status = $term->save();
      });

      if (is_null($terms)) {
        // @codeCoverageIgnoreStart
        $save_status = $term->save();
        // @codeCoverageIgnoreEnd
      }

      if ($save_status) {
        $updatedAttrs .= $attr_array['field_attribute_code']['value'] . ", ";
      }
    }

    return $updatedAttrs;
  }
public function createAttributesFromTabs(array $attrib_data = []) {
    // Return value.
    $updatedAttrs = "";

    $save_status = FALSE;

    foreach ($attrib_data as $attr_key => $attribute) {

      $attr_array = [
        'field_attribute_code' => ['value' => $attribute->code],
        'field_attribute_brand' => ['value' => $attribute->brand],
        'field_attribute_labl' => ['value' => $attribute->label],
        'field_attribute_group' => ['value' => $attribute->group],
        'field_attribute_type' => ['value' => $attribute->type],
      ];

      // TODO: make this a configurable option or let the admin specify it.
      $attr_array['vid'] = $this::ATTRIBUTE_VOCAB_ID;
      // The name is needed by the Drupal Taxonomy API.
      $attr_array['name'] = $attribute->label;

      $term = Term::create($attr_array);

      // Modify terms of the same name if they already exist.
      $terms = self::loadTermsByNames($this::ATTRIBUTE_VOCAB_ID, [$attr_array['name']], function (&$term) use ($attr_array, &$save_status) {
        $term->get('field_attribute_code')->setValue($attr_array['field_attribute_code']);
        $term->get('field_attribute_brand')->setValue($attr_array['field_attribute_brand']);
        $term->get('field_attribute_labl')->setValue($attr_array['field_attribute_labl']);
        $term->get('field_attribute_group')->setValue($attr_array['field_attribute_group']);
        $term->get('field_attribute_type')->setValue($attr_array['field_attribute_type']);

        $save_status = $term->save();
      });

      if (is_null($terms)) {
        // @codeCoverageIgnoreStart
        $save_status = $term->save();
        // @codeCoverageIgnoreEnd
      }

      if ($save_status) {
        $updatedAttrs .= $attr_array['field_attribute_code']['value'] . ", ";
      }
    }

    return $updatedAttrs;
  }
public function createAttributesFromTabs ( array $ attrib_data = [ ] ) { // Return value. $ updatedAttrs = "" ; $ save_status = FALSE ; foreach ( $ attrib_data as $ attr_key => $ attribute ) { $ attr_array = [ 'field_attribute_code' => [ 'value' => $ attribute -> code ] , 'field_attribute_brand' => [ 'value' => $ attribute -> brand ] , 'field_attribute_labl' => [ 'value' => $ attribute -> label ] , 'field_attribute_group' => [ 'value' => $ attribute -> group ] , 'field_attribute_type' => [ 'value' => $ attribute -> type ] , ] ; // TODO: make this a configurable option or let the admin specify it. $ attr_array [ 'vid' ] = $ this :: ATTRIBUTE_VOCAB_ID ; // The name is needed by the Drupal Taxonomy API. $ attr_array [ 'name' ] = $ attribute -> label ; $ term = Term :: create ( $ attr_array ) ; // Modify terms of the same name if they already exist. $ terms = self :: loadTermsByNames ( $ this :: ATTRIBUTE_VOCAB_ID , [ $ attr_array [ 'name' ] ] , function ( & $ term ) use ( $ attr_array , & $ save_status ) { $ term -> get ( 'field_attribute_code' ) -> setValue ( $ attr_array [ 'field_attribute_code' ] ) ; $ term -> get ( 'field_attribute_brand' ) -> setValue ( $ attr_array [ 'field_attribute_brand' ] ) ; $ term -> get ( 'field_attribute_labl' ) -> setValue ( $ attr_array [ 'field_attribute_labl' ] ) ; $ term -> get ( 'field_attribute_group' ) -> setValue ( $ attr_array [ 'field_attribute_group' ] ) ; $ term -> get ( 'field_attribute_type' ) -> setValue ( $ attr_array [ 'field_attribute_type' ] ) ; $ save_status = $ term -> save ( ) ; } ) ; if ( is_null ( $ terms ) ) { // @codeCoverageIgnoreStart $ save_status = $ term -> save ( ) ; // @codeCoverageIgnoreEnd } if ( $ save_status ) { $ updatedAttrs .= $ attr_array [ 'field_attribute_code' ] [ 'value' ] . ", " ; } } return $ updatedAttrs ; }
Populates the cottage_attributes taxonomy with data from TABS.

@param array $attrib_data
The response array retrieved from TABS.

@return string
A comma separated list of created/updated entries in the taxonomy.

@throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
@throws \Drupal\Core\Entity\EntityStorageException
@throws \Drupal\Core\Entity\Exception\AmbiguousEntityClassException
@throws \Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException
Populates the cottage_attributes taxonomy with data from TABS .