Skip to content

Commit

Permalink
Merge pull request #131 from moderntribe/s7/MOOSE/terms-block-errors
Browse files Browse the repository at this point in the history
[FIX] Terms Block
  • Loading branch information
GeoffDusome authored Mar 13, 2024
2 parents 3d3f076 + d10dc76 commit 9375eb6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). Each changelog entry gets prefixed with the category of the item (Added, Changed, Depreciated, Removed, Fixed, Security).

## [2024.03]
- Fixed: Fixed an issue with the Terms block where if a post ID wasn't provided it would error out. [Panopto Slack thread.](https://tribe.slack.com/archives/C061UC7B2F9/p1710250320818599)
- Added: Styling for editor title bar (http://p.tri.be/i/Dszjax). [[MOOSE-111]](https://moderntribe.atlassian.net/browse/MOOSE-111)
- Added: Allow `view.js` files for blocks. [[MOOSE-86]](https://moderntribe.atlassian.net/browse/MOOSE-86)
- Changed: `render_template` function for ACF blocks should now properly pass in all block variables. [[MOOSE-81]](https://moderntribe.atlassian.net/browse/MOOSE-81)
Expand Down
10 changes: 8 additions & 2 deletions wp-content/plugins/core/src/Blocks/Terms_Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ public function __construct( array $block_attributes ) {
* @return \WP_Term[]
*/
public function get_the_terms(): array {
$post_id = get_the_ID();

if ( ! $post_id ) {
return $this->terms;
}

if ( $this->only_primary_term ) {
$term = $this->get_primary_term( get_the_ID(), $this->taxonomy );
$term = $this->get_primary_term( $post_id, $this->taxonomy );
if ( $term ) {
$this->terms[] = $term;
}
} else {
$terms = get_the_terms( get_the_ID(), $this->taxonomy );
$terms = get_the_terms( $post_id, $this->taxonomy );
if ( $terms && ! is_wp_error( $terms ) ) {
$this->terms = $terms;
}
Expand Down
9 changes: 6 additions & 3 deletions wp-content/themes/core/blocks/tribe/terms/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
},
"attributes": {
"taxonomyToUse": {
"type": "string"
"type": "string",
"default": "category"
},
"onlyPrimaryTerm": {
"type": "boolean"
"type": "boolean",
"default": false
},
"hasLinks": {
"type": "boolean"
"type": "boolean",
"default": false
}
},
"styles": [ { "name": "pills", "label": "Pills" } ],
Expand Down
16 changes: 10 additions & 6 deletions wp-content/themes/core/blocks/tribe/terms/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ export default function Edit( {
taxonomyToUse: newValue,
} );
} }
options={ taxonomies.map( ( taxonomy ) => {
return {
label: taxonomy.name,
value: taxonomy.slug,
};
} ) }
options={
taxonomies
? taxonomies.map( ( taxonomy ) => {
return {
label: taxonomy.name,
value: taxonomy.slug,
};
} )
: []
}
/>
<ToggleControl
label={ __(
Expand Down

0 comments on commit 9375eb6

Please sign in to comment.