jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/399215 )

Change subject: Handle EntityHolder containing Forms in LexemeHandler
......................................................................


Handle EntityHolder containing Forms in LexemeHandler

Change-Id: I26f9b7222d3b95b81a4c2f37076ce04fd798e23e
---
M WikibaseLexeme.entitytypes.php
M src/Content/LexemeHandler.php
M src/DataModel/Form.php
M tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
4 files changed, 43 insertions(+), 0 deletions(-)

Approvals:
  jenkins-bot: Verified
  Thiemo Kreuz (WMDE): Looks good to me, approved



diff --git a/WikibaseLexeme.entitytypes.php b/WikibaseLexeme.entitytypes.php
index d043e7d..8567e80 100644
--- a/WikibaseLexeme.entitytypes.php
+++ b/WikibaseLexeme.entitytypes.php
@@ -106,6 +106,7 @@
                                $wikibaseRepo->getValidatorErrorLocalizer(),
                                $wikibaseRepo->getEntityIdParser(),
                                $wikibaseRepo->getEntityIdLookup(),
+                               $wikibaseRepo->getEntityLookup(),
                                
$wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory(),
                                new LexemeFieldDefinitions()
                        );
@@ -224,5 +225,19 @@
                'entity-patcher-strategy-builder' => function () {
                        return new FormPatcher();
                },
+               'content-handler-factory-callback' => function () {
+                       $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+                       return new LexemeHandler(
+                               $wikibaseRepo->getStore()->getTermIndex(),
+                               $wikibaseRepo->getEntityContentDataCodec(),
+                               $wikibaseRepo->getEntityConstraintProvider(),
+                               $wikibaseRepo->getValidatorErrorLocalizer(),
+                               $wikibaseRepo->getEntityIdParser(),
+                               $wikibaseRepo->getEntityIdLookup(),
+                               $wikibaseRepo->getEntityLookup(),
+                               
$wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory(),
+                               new LexemeFieldDefinitions()
+                       );
+               },
        ],
 ];
diff --git a/src/Content/LexemeHandler.php b/src/Content/LexemeHandler.php
index e4133b2..d8f5302 100644
--- a/src/Content/LexemeHandler.php
+++ b/src/Content/LexemeHandler.php
@@ -6,9 +6,14 @@
 use IContextSource;
 use Page;
 use Wikibase\Content\EntityHolder;
+use Wikibase\Content\EntityInstanceHolder;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityIdParser;
+use Wikibase\DataModel\Services\Lookup\EntityLookup;
 use Wikibase\EditEntityAction;
 use Wikibase\HistoryEntityAction;
+use Wikibase\Lexeme\DataModel\Form;
+use Wikibase\Lexeme\DataModel\FormId;
 use Wikibase\Lexeme\Search\LexemeFieldDefinitions;
 use Wikibase\Lib\Store\EntityContentDataCodec;
 use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
@@ -33,6 +38,12 @@
         * @var EntityIdLookup
         */
        private $entityIdLookup;
+
+       /**
+        * @var EntityLookup
+        */
+       private $entityLookup;
+
        /**
         * @var LanguageFallbackLabelDescriptionLookupFactory
         */
@@ -45,6 +56,7 @@
         * @param ValidatorErrorLocalizer $errorLocalizer
         * @param EntityIdParser $entityIdParser
         * @param EntityIdLookup $entityIdLookup
+        * @param EntityLookup $entityLookup
         * @param LanguageFallbackLabelDescriptionLookupFactory 
$labelLookupFactory
         * @param LexemeFieldDefinitions $fieldDefinitions
         * @param callable|null $legacyExportFormatDetector
@@ -56,6 +68,7 @@
                ValidatorErrorLocalizer $errorLocalizer,
                EntityIdParser $entityIdParser,
                EntityIdLookup $entityIdLookup,
+               EntityLookup $entityLookup,
                LanguageFallbackLabelDescriptionLookupFactory 
$labelLookupFactory,
                LexemeFieldDefinitions $fieldDefinitions,
                $legacyExportFormatDetector = null
@@ -71,6 +84,7 @@
                        $legacyExportFormatDetector
                );
                $this->entityIdLookup = $entityIdLookup;
+               $this->entityLookup = $entityLookup;
                $this->labelLookupFactory = $labelLookupFactory;
        }
 
@@ -116,9 +130,19 @@
         * @return LexemeContent
         */
        protected function newEntityContent( EntityHolder $entityHolder = null 
) {
+               if ( $entityHolder !== null && $entityHolder->getEntityType() 
=== Form::ENTITY_TYPE ) {
+                       $lexemeId = $this->getLexemeId( 
$entityHolder->getEntityId() );
+                       $entityHolder = new EntityInstanceHolder( 
$this->entityLookup->getEntity( $lexemeId ) );
+               }
                return new LexemeContent( $entityHolder );
        }
 
+       private function getLexemeId( FormId $formId ) {
+               $parts = EntityId::splitSerialization( $formId->getLocalPart() 
);
+               $parts = explode( '-', $parts[2], 2 );
+               return new LexemeId( $parts[0] );
+       }
+
        /**
         * @param string $id
         *
diff --git a/src/DataModel/Form.php b/src/DataModel/Form.php
index e808783..b9b5879 100644
--- a/src/DataModel/Form.php
+++ b/src/DataModel/Form.php
@@ -21,6 +21,8 @@
  */
 class Form implements EntityDocument, StatementListProvider {
 
+       const ENTITY_TYPE = 'form';
+
        /**
         * @var FormId
         */
diff --git a/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php 
b/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
index 1b25596..efa908f 100644
--- a/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
+++ b/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
@@ -6,6 +6,7 @@
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityIdParser;
 use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Services\Lookup\EntityLookup;
 use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
 use Wikibase\DataModel\Term\Term;
 use Wikibase\DataModel\Term\TermList;
@@ -147,6 +148,7 @@
                        $this->getMock( ValidatorErrorLocalizer::class ),
                        $this->getMock( EntityIdParser::class ),
                        $this->getMock( EntityIdLookup::class ),
+                       $this->getMock( EntityLookup::class ),
                        $labelLookupFactory,
                        new LexemeFieldDefinitions()
                );

-- 
To view, visit https://gerrit.wikimedia.org/r/399215
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I26f9b7222d3b95b81a4c2f37076ce04fd798e23e
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: WMDE-leszek <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Thiemo Kreuz (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to