diff --git a/src/Plugin/Field/FieldFormatter/CollectDataFormatter.php b/src/Plugin/Field/FieldFormatter/CollectDataFormatter.php index 44ac5ae..6f59b4e 100644 --- a/src/Plugin/Field/FieldFormatter/CollectDataFormatter.php +++ b/src/Plugin/Field/FieldFormatter/CollectDataFormatter.php @@ -107,7 +107,7 @@ class CollectDataFormatter extends FormatterBase implements ContainerFactoryPlug // If schema plugin has custom build method, use it to build the // output. $elements[$delta]['plugin']['#title'] = $this->t('Specialized display'); - $elements[$delta]['plugin']['data'] = $schema_plugin->build($schema_plugin->parse($item)); + $elements[$delta]['plugin']['data'] = $schema_plugin->build($schema_plugin->parse($item), $item->getEntity()); } else { // If there is no custom build method, build a simple table of the diff --git a/src/Plugin/collect/Schema/FetchUrlSchema.php b/src/Plugin/collect/Schema/FetchUrlSchema.php index cd60025..61f2461 100644 --- a/src/Plugin/collect/Schema/FetchUrlSchema.php +++ b/src/Plugin/collect/Schema/FetchUrlSchema.php @@ -6,6 +6,7 @@ namespace Drupal\collect\Plugin\collect\Schema; +use Drupal\collect\CollectContainerInterface; use Drupal\collect\Plugin\Field\FieldType\CollectDataItem; use Drupal\collect\Schema\SpecializedDisplaySchemaInterface; use Drupal\collect\Schema\SchemaBase; @@ -43,7 +44,7 @@ class FetchUrlSchema extends SchemaBase implements SpecializedDisplaySchemaInter /** * {@inheritdoc} */ - public function build($data) { + public function build($data, CollectContainerInterface $collect_container) { if (empty($data)) { return; } @@ -96,8 +97,7 @@ class FetchUrlSchema extends SchemaBase implements SpecializedDisplaySchemaInter } // The response body. - $collect_container_id = \Drupal::requestStack()->getCurrentRequest()->get('collect_container')->id(); - $url = \Drupal::url('collect.generate_page', ['collect_container' => $collect_container_id], ['absolute' => TRUE]); + $url = \Drupal::url('collect.generate_page', ['collect_container' => $collect_container->id()], ['absolute' => TRUE]); $output['body'] = array( '#type' => 'link', '#attributes' => array( diff --git a/src/Plugin/collect/Schema/FieldDefinitionSchema.php b/src/Plugin/collect/Schema/FieldDefinitionSchema.php index 5f5947e..b27f960 100644 --- a/src/Plugin/collect/Schema/FieldDefinitionSchema.php +++ b/src/Plugin/collect/Schema/FieldDefinitionSchema.php @@ -6,6 +6,7 @@ namespace Drupal\collect\Plugin\collect\Schema; +use Drupal\collect\CollectContainerInterface; use Drupal\collect\Plugin\Field\FieldType\CollectDataItem; use Drupal\collect\Schema\SpecializedDisplaySchemaInterface; use Drupal\collect\Schema\SchemaBase; @@ -70,7 +71,7 @@ class FieldDefinitionSchema extends SchemaBase implements SpecializedDisplaySche /** * {@inheritdoc} */ - public function build($definition) { + public function build($definition, CollectContainerInterface $collect_container) { $output = array(); foreach ($definition['fields'] as $id => $value) { $output['fields'][$id] = array( diff --git a/src/Schema/SpecializedDisplaySchemaInterface.php b/src/Schema/SpecializedDisplaySchemaInterface.php index cb055cd..e3d5e4e 100644 --- a/src/Schema/SpecializedDisplaySchemaInterface.php +++ b/src/Schema/SpecializedDisplaySchemaInterface.php @@ -5,6 +5,7 @@ */ namespace Drupal\collect\Schema; +use Drupal\collect\CollectContainerInterface; /** * Defines methods for schema plugins that have special display code. @@ -16,10 +17,12 @@ interface SpecializedDisplaySchemaInterface extends SchemaInterface { * * @param mixed $data * Any parsed data having this schema. + * @param \Drupal\collect\CollectContainerInterface $collect_container + * A collect container object. * * @return array * A renderable array representing the content. */ - public function build($data); + public function build($data, CollectContainerInterface $collect_container); } diff --git a/tests/modules/collect_test/src/Plugin/collect/Schema/TestSpecializedDisplaySchema.php b/tests/modules/collect_test/src/Plugin/collect/Schema/TestSpecializedDisplaySchema.php index fe7f7bd..cdf1f0e 100644 --- a/tests/modules/collect_test/src/Plugin/collect/Schema/TestSpecializedDisplaySchema.php +++ b/tests/modules/collect_test/src/Plugin/collect/Schema/TestSpecializedDisplaySchema.php @@ -7,6 +7,7 @@ namespace Drupal\collect_test\Plugin\collect\Schema; +use Drupal\collect\CollectContainerInterface; use Drupal\collect\Schema\SpecializedDisplaySchemaInterface; /** @@ -25,7 +26,7 @@ class TestSpecializedDisplaySchema extends TestSchema implements SpecializedDisp /** * {@inheritdoc} */ - public function build($data) { + public function build($data, CollectContainerInterface $collect_container) { return array( '#type' => 'item', '#markup' => "Let me say " . $data['greeting'],