Skip to content

Commit

Permalink
Rename get_content to set_content, add construct filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhned committed Oct 3, 2017
1 parent 59d74cc commit ef11473
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 28 deletions.
8 changes: 8 additions & 0 deletions src/CategoryList.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public function __construct( $name = 'category-list', $delimiter = ', ', $parent
$this->parents = $parents;
$this->parents_order = $parents_order;
$this->include_links = $include_links;
}

/**
* Get the content.
*
* @return string
*/
public function set_content() {

if ( true === $this->include_links ) {
$this->content = get_the_category_list( $this->delimiter, $this->parents, $this->data );
Expand Down
4 changes: 2 additions & 2 deletions src/EventDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function __construct( $name = 'event-date', $event_start, $event_end, $ev
$this->event_all_day = $event_all_day;

$this->event_date_type = Utilities::set_event_date_type( $this->event_start, $this->event_end, $this->event_all_day );
$this->get_content();
$this->set_content();
}

/**
* Get the correct format based on the type of event.
*/
public function get_content() {
public function set_content() {

switch ( $this->event_date_type ) {

Expand Down
17 changes: 12 additions & 5 deletions src/Organism.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public function __construct( $name = '', $data = null, $content = '', $tag = 'di
$this->prepend = $prepend;
$this->append = $append;
$this->after = $after;

// Filter the construct method if you need to change something at the beginning.
$this->do_filter('-construct');
}

/**
Expand All @@ -143,7 +146,7 @@ public function __construct( $name = '', $data = null, $content = '', $tag = 'di
*/
public function get_markup() {

$this->get_content();
$this->set_content();

// Note: If a child organism overwrites get_markup, please include Organism->do_filter so that we don't have a filterless Organism.
$this->do_filter();
Expand Down Expand Up @@ -222,14 +225,18 @@ public function get_attributes() {
}

/**
* Gets the content.
* Sets the content.
* This is a placeholder method: it only exists so that child classes can overwrite it.
* Child classes that use this method do not have to return parent::get_content.
* Child classes that use this method do not have to return parent::set_content.
*/
public function set_content() {}

/**
* Gets the content (for child classes).
*
* @return string
*/
public function get_content() {

public function return_content() {
return $this->content;
}

Expand Down
2 changes: 1 addition & 1 deletion src/PostAuthor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct( $name = 'post-author', $author_meta = 'display_name
/**
* Set up author content.
*/
public function get_content() {
public function set_content() {

// The other alternative for $data is if an author id has been passed in directly.
// This is so that child classes (PostAuthorLink) can pass in their own content, if they need to.
Expand Down
2 changes: 1 addition & 1 deletion src/PostDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct( $name = 'post-date', $date_format = '' ) {
/**
* Sets up the content.
*/
public function get_content() {
public function set_content() {

$this->content = get_the_date( $this->date_format, $this->data );
}
Expand Down
4 changes: 2 additions & 2 deletions src/PostTermSingle.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public function get_term() {
}

/**
* Gets the content.
* Sets the content.
*/
public function get_content() {
public function set_content() {

// This catches objects that are passed in, and if we didn't pass anything in.
if ( is_object( $this->data ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/PostThumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct( $name = 'post-thumbnail', $data = null, $size = 'po
/**
* Set up the content.
*/
public function get_content() {
public function set_content() {

// This uses call_user_func so that $attr can be passed in as an array. Pretty sure that's why.
$this->content = call_user_func( 'get_the_post_thumbnail', $this->data, $this->size, $this->attr );
Expand Down
4 changes: 2 additions & 2 deletions src/PostTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function __construct( $name = 'posttitle', $data = null ) {
}

/**
* Gets the content.
* Sets the content.
*/
public function get_content() {
public function set_content() {

$this->content = get_the_title( $this->data );
}
Expand Down
18 changes: 11 additions & 7 deletions src/PostTitleLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ public function __construct( $name = 'posttitle-link' ) {

parent::__construct( $name );

$this->post_link = new LinkPost( $this->organism_name( 'anchor' ), $this->content, [], $this->data );
$this->structure = [ $this->post_link ];

}

/**
* Gets the post title from the parent class first, then generates and adds the link to the content based off of that.
*
* @return string
*/
public function get_content() {
public function set_content() {

$this->content = parent::get_content();
$this->post_link = new LinkPost( $this->organism_name( 'anchor' ), $this->content, [], $this->data );
$this->content = $this->post_link->get_markup();
// Get the post title from the parent
parent::set_content();

// Pass the post title in to the post link
$this->post_link->content = $this->content;

return Organism::get_content();
// Clear out the content so we don't duplicate it
$this->content = '';
}
}
2 changes: 1 addition & 1 deletion src/SchemaAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct( $name = 'schema-address', $data = null ) {
/**
* Assemble the address schema block
*/
public function get_content() {
public function set_content() {

$address_pieces = array();

Expand Down
4 changes: 2 additions & 2 deletions src/ShareLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public function __construct( $name = 'share-link', $network, $href_base, $share_
}

/**
* Gets the content.
* Sets the content.
*/
public function get_content() {
public function set_content() {

$this->build_link_target();
$this->substitute_icon_in_content();
Expand Down
2 changes: 1 addition & 1 deletion src/TaxonomyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct( $name = 'taxonomy-list', $taxonomy = '', $delimiter
/**
* Gets the list.
*/
public function get_content() {
public function set_content() {

$terms_arr = get_the_terms( $this->data, $this->taxonomy );
$term_names_arr = array();
Expand Down
2 changes: 1 addition & 1 deletion src/TaxonomyListWithLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct( $name = 'taxonomy-list-with-links', $taxonomy = nul
/**
* Gets the term list.
*/
public function get_content() {
public function set_content() {

$this->content = get_the_term_list( $this->data, $this->taxonomy, $this->prepend, $this->delimiter, $this->append );
}
Expand Down
2 changes: 1 addition & 1 deletion src/WPListPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct( $name = 'wp-list-pages', $list_args ) {
/**
* Get the content.
*/
public function get_content() {
public function set_content() {

$this->content = wp_list_pages( $this->list_vars );
}
Expand Down
2 changes: 1 addition & 1 deletion src/WPListTerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function resolve_taxonomy() {
/**
* Get the content.
*/
public function get_content() {
public function set_content() {

if ( '' !== $this->taxonomy ) {
$this->resolve_taxonomy();
Expand Down

0 comments on commit ef11473

Please sign in to comment.