You are here

Material.php in farmOS 2.x

File

modules/quantity/material/src/Plugin/Quantity/QuantityType/Material.php
View source
<?php

namespace Drupal\farm_quantity_material\Plugin\Quantity\QuantityType;

use Drupal\farm_entity\Plugin\Quantity\QuantityType\FarmQuantityType;

/**
 * Provides the material quantity type.
 *
 * @QuantityType(
 *   id = "material",
 *   label = @Translation("Material"),
 * )
 */
class Material extends FarmQuantityType {

  /**
   * {@inheritdoc}
   */
  public function buildFieldDefinitions() {

    // Inherit default quantity fields.
    $fields = parent::buildFieldDefinitions();

    // Material type.
    $options = [
      'type' => 'entity_reference',
      'label' => $this
        ->t('Material type'),
      'description' => $this
        ->t('What type of materials are being applied?'),
      'target_type' => 'taxonomy_term',
      'target_bundle' => 'material_type',
      'auto_create' => TRUE,
      'weight' => [
        'form' => -50,
        'view' => -50,
      ],
    ];
    $fields['material_type'] = $this->farmFieldFactory
      ->bundleFieldDefinition($options);
    return $fields;
  }

}

Classes

Namesort descending Description
Material Provides the material quantity type.