/** * Provides a label for a property by its relationship to a context. * * @param \Drupal\Core\Field\BaseFieldDefinition $property * The property for which to generate a label. * @param \Drupal\Core\Plugin\Context\ContextInterface $context * The context to which the property is related. * @param $context_id * The context from the previous parameter's id in the contexts array. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * A label for this property for use in user interfaces. */ protected function getRelatedPropertyLabel(BaseFieldDefinition $property, ContextInterface $context, $context_id) { /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */ $label = $property->getFieldStorageDefinition()->getLabel(); $string = "@context_id: {$label->getUntranslatedString()}"; $args = $label->getArguments(); $args['@context_id'] = !empty($context->getContextDefinition()->getLabel()) ? $context->getContextDefinition()->getLabel() : "{$context_id}"; $options = $label->getOptions(); // @todo we need to really think about this label. It informs the UI extensively and should be as clear as possible. return $this->translation->translate($string, $args, $options); }