added languagemap sugar
This commit is contained in:
parent
6cbe66d121
commit
af66737939
1 changed files with 47 additions and 0 deletions
|
@ -33,6 +33,13 @@ class Base_Object {
|
||||||
*/
|
*/
|
||||||
protected $_skip_next;
|
protected $_skip_next;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if this is set, the language maps will be set automatically with this language if not set yet todo nicer description
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $_default_language_code_for_language_maps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object's unique global identifier
|
* The object's unique global identifier
|
||||||
*
|
*
|
||||||
|
@ -534,11 +541,51 @@ class Base_Object {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( 'content' === $key || 'summary' === $key || 'name' === $key ) { // todo nicer?
|
||||||
|
$this->set_basic_language_map( $key, $value ); // todo skip setter if language map is already set
|
||||||
|
}
|
||||||
|
|
||||||
$this->$key = $value;
|
$this->$key = $value;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for the languageMap default language
|
||||||
|
*
|
||||||
|
* @param string $languagecode languageocde for default
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function set_default_language_for_maps( $languagecode ) {
|
||||||
|
$this->_default_language_code_for_language_maps = $languagecode;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic languageMap setter.
|
||||||
|
*
|
||||||
|
* @param string $key The key for the language map.
|
||||||
|
* @param string $value The value to set.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function set_basic_language_map( $key, $value ) {
|
||||||
|
// todo better name, implement usage for content, summary and name
|
||||||
|
$mapkey = $key . '_map';
|
||||||
|
|
||||||
|
if ( ! isset( $this->_default_language_code_for_language_maps ) ) {
|
||||||
|
return new WP_Error( '_default_language_code_for_language_maps must be set before calling set_languageMap', __( '_default_language_code_for_language_maps must be set before calling set_languageMap', 'activitypub' ), array( 'status' => 404 ) );
|
||||||
|
}
|
||||||
|
if ( ! $this->has( $mapkey ) ) {
|
||||||
|
return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->$mapkey = array(
|
||||||
|
$this->_default_language_code_for_language_maps => $value,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic adder.
|
* Generic adder.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue