-
Notifications
You must be signed in to change notification settings - Fork 5
add Elementor posts widget support (WP-999) #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0accb1b
add Elementor posts widget support (WP-999)
vsolovei-smartling 80fe72c
bump version, add readme (WP-999)
vsolovei-smartling 9b0155c
revert text change (WP-999)
vsolovei-smartling bb66434
add posts_include_term_ids processing to elementor posts widget (WP-999)
vsolovei-smartling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?php | ||
|
|
||
| namespace Smartling\ContentTypes\Elementor\Elements; | ||
|
|
||
| use Smartling\ContentTypes\ContentTypeHelper; | ||
| use Smartling\Models\Content; | ||
| use Smartling\Models\RelatedContentInfo; | ||
|
|
||
| class Posts extends Unknown | ||
| { | ||
| public function getType(): string | ||
| { | ||
| return 'posts'; | ||
| } | ||
|
|
||
| public function getRelated(): RelatedContentInfo | ||
| { | ||
| $return = parent::getRelated(); | ||
| $key = 'custom_skin_template'; | ||
| $id = $this->getIntSettingByKey($key, $this->settings); | ||
| if ($id !== null) { | ||
| $return->addContent(new Content($id, ContentTypeHelper::CONTENT_TYPE_UNKNOWN), $this->id, "settings/$key"); | ||
| } | ||
|
|
||
| $key = 'posts_include_term_ids'; | ||
| foreach ($this->settings[$key] ?? [] as $index => $termId) { | ||
| if (is_numeric($termId)) { | ||
| $return->addContent(new Content((int)$termId, ContentTypeHelper::CONTENT_TYPE_TAXONOMY), $this->id, "settings/$key/$index"); | ||
| } | ||
| } | ||
|
|
||
| return $return; | ||
| } | ||
|
|
||
| public function getTranslatableStrings(): array | ||
| { | ||
| return [$this->id => $this->getTranslatableStringsByKeys([ | ||
| 'classic_read_more_text', | ||
| 'cards_read_more_text', | ||
| 'pagination_prev_label', | ||
| 'pagination_next_label', | ||
| 'text', | ||
| 'load_more_no_posts_custom_message', | ||
| 'loadmore_text', | ||
| 'loadmore_loading_text', | ||
| ])]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <?php | ||
|
|
||
| namespace Smartling\ContentTypes\Elementor; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Smartling\ContentTypes\ContentTypeHelper; | ||
| use Smartling\ContentTypes\Elementor\Elements\Posts; | ||
| use Smartling\ContentTypes\ExternalContentElementor; | ||
| use Smartling\Models\RelatedContentInfo; | ||
| use Smartling\Submissions\SubmissionEntity; | ||
|
|
||
| class PostsTest extends TestCase | ||
| { | ||
| private function makeWidget(array $settings = []): Posts | ||
| { | ||
| return new Posts([ | ||
| 'id' => 'abc123', | ||
| 'elType' => 'widget', | ||
| 'widgetType' => 'posts', | ||
| 'settings' => $settings, | ||
| 'elements' => [], | ||
| ]); | ||
| } | ||
|
|
||
| public function testGetType(): void | ||
| { | ||
| $this->assertEquals('posts', $this->makeWidget()->getType()); | ||
| } | ||
|
|
||
| public function testGetTranslatableStrings(): void | ||
| { | ||
| $strings = $this->makeWidget([ | ||
| 'classic_read_more_text' => 'Read More »', | ||
| 'cards_read_more_text' => 'Read More »', | ||
| 'pagination_prev_label' => '« Previous', | ||
| 'pagination_next_label' => 'Next »', | ||
| 'text' => 'Load More', | ||
| 'load_more_no_posts_custom_message' => 'No more posts to show', | ||
| 'loadmore_text' => 'Load More', | ||
| 'loadmore_loading_text' => 'Loading...', | ||
| ])->getTranslatableStrings(); | ||
|
|
||
| $this->assertEquals([ | ||
| 'classic_read_more_text' => 'Read More »', | ||
| 'cards_read_more_text' => 'Read More »', | ||
| 'pagination_prev_label' => '« Previous', | ||
| 'pagination_next_label' => 'Next »', | ||
| 'text' => 'Load More', | ||
| 'load_more_no_posts_custom_message' => 'No more posts to show', | ||
| 'loadmore_text' => 'Load More', | ||
| 'loadmore_loading_text' => 'Loading...', | ||
| ], $strings['abc123']); | ||
| } | ||
|
|
||
| public function testGetTranslatableStringsEmpty(): void | ||
| { | ||
| $this->assertEquals([], $this->makeWidget()->getTranslatableStrings()['abc123']); | ||
| } | ||
|
|
||
| public function testGetRelatedReturnsTemplateId(): void | ||
| { | ||
| $related = $this->makeWidget(['custom_skin_template' => '9165'])->getRelated(); | ||
|
|
||
| $this->assertEquals( | ||
| [ContentTypeHelper::CONTENT_TYPE_UNKNOWN => [9165]], | ||
| $related->getRelatedContentList() | ||
| ); | ||
| } | ||
|
|
||
| public function testGetRelatedNoTemplateReturnsEmpty(): void | ||
| { | ||
| $related = $this->makeWidget()->getRelated(); | ||
|
|
||
| $this->assertEquals([], $related->getRelatedContentList()); | ||
| } | ||
|
|
||
| public function testGetRelatedReturnsTermIds(): void | ||
| { | ||
| $related = $this->makeWidget(['posts_include_term_ids' => [42, 99]])->getRelated(); | ||
|
|
||
| $this->assertEquals( | ||
| [ContentTypeHelper::CONTENT_TYPE_TAXONOMY => [42, 99]], | ||
| $related->getRelatedContentList() | ||
| ); | ||
| } | ||
|
|
||
| public function testGetRelatedSkipsNonNumericTermIds(): void | ||
| { | ||
| $related = $this->makeWidget(['posts_include_term_ids' => ['invalid', 42]])->getRelated(); | ||
|
|
||
| $this->assertEquals( | ||
| [ContentTypeHelper::CONTENT_TYPE_TAXONOMY => [42]], | ||
| $related->getRelatedContentList() | ||
| ); | ||
| } | ||
|
|
||
| public function testGetRelatedReturnsBothTemplateAndTermIds(): void | ||
| { | ||
| $related = $this->makeWidget([ | ||
| 'custom_skin_template' => '9165', | ||
| 'posts_include_term_ids' => ["42", 99], | ||
| ])->getRelated(); | ||
|
|
||
| $this->assertEquals( | ||
| [ | ||
| ContentTypeHelper::CONTENT_TYPE_UNKNOWN => [9165], | ||
| ContentTypeHelper::CONTENT_TYPE_TAXONOMY => [42, 99], | ||
| ], | ||
| $related->getRelatedContentList() | ||
| ); | ||
| } | ||
|
|
||
| public function testSetTargetContent(): void | ||
| { | ||
| $result = $this->makeWidget([ | ||
| 'text' => 'Load More', | ||
| 'loadmore_loading_text' => 'Loading...', | ||
| ])->setTargetContent( | ||
| $this->createMock(ExternalContentElementor::class), | ||
| new RelatedContentInfo([]), | ||
| ['abc123' => ['text' => 'Cargar más', 'loadmore_loading_text' => 'Cargando...']], | ||
| $this->createMock(SubmissionEntity::class), | ||
| )->toArray(); | ||
|
|
||
| $this->assertEquals('Cargar más', $result['settings']['text']); | ||
| $this->assertEquals('Cargando...', $result['settings']['loadmore_loading_text']); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like
5.4.0- new functionality with no breaking bc.