Loading modules/decoupled_toolbox_weight/decoupled_toolbox_weight.info.yml 0 → 100644 +8 −0 Original line number Diff line number Diff line name: 'Decoupled Toolbox for Weight' type: module description: 'Makes Weight compatible with Decoupled Toolbox.' core_version_requirement: ">=8" package: 'Decoupled' dependencies: - decoupled_toolbox:decoupled_toolbox - weight:weight modules/decoupled_toolbox_weight/src/Plugin/Field/FieldFormatter/WeightDecoupledFormatter.php 0 → 100755 +34 −0 Original line number Diff line number Diff line <?php namespace Drupal\decoupled_toolbox_weight\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemInterface; use Drupal\decoupled_toolbox\Exception\InvalidContentException; use Drupal\decoupled_toolbox\Plugin\Field\FieldFormatter\GenericDecoupledFormatter; use Drupal\weight\Plugin\Field\FieldType\WeightItem; /** * Plugin implementation of the 'decoupled_weight' formatter. * * @FieldFormatter( * id = "decoupled_weight", * label = @Translation("Weight decoupled formatter"), * field_types = { * "weight", * } * ) */ class WeightDecoupledFormatter extends GenericDecoupledFormatter { /** * {@inheritdoc} */ protected function viewFieldItem(FieldItemInterface $item) { if (!$item instanceof WeightItem) { throw new InvalidContentException($this->t('Not a valid weight field item.')); } return (int) $item->getString(); } } Loading
modules/decoupled_toolbox_weight/decoupled_toolbox_weight.info.yml 0 → 100644 +8 −0 Original line number Diff line number Diff line name: 'Decoupled Toolbox for Weight' type: module description: 'Makes Weight compatible with Decoupled Toolbox.' core_version_requirement: ">=8" package: 'Decoupled' dependencies: - decoupled_toolbox:decoupled_toolbox - weight:weight
modules/decoupled_toolbox_weight/src/Plugin/Field/FieldFormatter/WeightDecoupledFormatter.php 0 → 100755 +34 −0 Original line number Diff line number Diff line <?php namespace Drupal\decoupled_toolbox_weight\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemInterface; use Drupal\decoupled_toolbox\Exception\InvalidContentException; use Drupal\decoupled_toolbox\Plugin\Field\FieldFormatter\GenericDecoupledFormatter; use Drupal\weight\Plugin\Field\FieldType\WeightItem; /** * Plugin implementation of the 'decoupled_weight' formatter. * * @FieldFormatter( * id = "decoupled_weight", * label = @Translation("Weight decoupled formatter"), * field_types = { * "weight", * } * ) */ class WeightDecoupledFormatter extends GenericDecoupledFormatter { /** * {@inheritdoc} */ protected function viewFieldItem(FieldItemInterface $item) { if (!$item instanceof WeightItem) { throw new InvalidContentException($this->t('Not a valid weight field item.')); } return (int) $item->getString(); } }