Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Updating the post object implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
funkjedi committed Oct 26, 2018
1 parent 8e69bed commit d6121ab
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 180 deletions.
50 changes: 50 additions & 0 deletions assets/acf_5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,56 @@ acf.registerFieldType(acf.models.ImageField.extend({
}));


acf.registerFieldType(acf.models.PostObjectField.extend({
type: 'qtranslate_post_object',

$input: function(){
return this.$('.acf-post-object.current-language select');
},

initialize: function(){
var self = this;

// vars
var $select = this.$input();

// inherit data
this.inherit( $select );

// select2
if( this.get('ui') ) {

// populate ajax_data (allowing custom attribute to already exist)
var ajaxAction = this.get('ajax_action');
if( !ajaxAction ) {
ajaxAction = 'acf/fields/' + this.get('type') + '/query';
}

// select2
this.select2 = [];
this.$('.acf-post-object select').each(function() {
self.select2.push(acf.newSelect2(self.$(this), {
field: self,
ajax: self.get('ajax'),
multiple: self.get('multiple'),
placeholder: self.get('placeholder'),
allowNull: self.get('allow_null'),
ajaxAction: ajaxAction,
}));
});
}
},

onRemove: function(){
if( this.select2 ) {
for (var i=0; i < this.select2.length; i++) {
this.select2[i].destroy();
}
}
}
}));


acf.registerFieldType(acf.models.UrlField.extend({
type: 'qtranslate_url',

Expand Down
8 changes: 7 additions & 1 deletion assets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@
.multi-language-field-wysiwyg .wp-switch-editor.current-language {
background-color: #f5f5f5;
border-bottom-color: #f5f5f5;
}
}

.multi-language-field-post-object .select2-container--default .select2-selection--multiple,
.multi-language-field-post-object .select2-container--default.select2-container--focus .select2-selection--multiple {
border-color: #ddd;
border-radius: 0;
}
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac

= 1.7.25 =
* Core: Added qTranslate suffix to field labels
* Core: (asedano) Added ACF5 support for Post Object field
* Bug Fix: Fixed issue with File fields

= 1.7.24 =
Expand Down
16 changes: 10 additions & 6 deletions src/acf_5/acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ public function include_fields() {
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/post_object.php';
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/text.php';
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/textarea.php';
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/wysiwyg.php';
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/url.php';
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/wysiwyg.php';

acf()->fields->register_field_type(new acf_qtranslate_acf_5_file($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_post_object($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_text($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_textarea($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_wysiwyg($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_file($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_url($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_post_object($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_wysiwyg($this->plugin));
}

/**
Expand All @@ -58,7 +58,9 @@ public function admin_enqueue_scripts() {
public function format_value($value) {
if (is_string($value)) {
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
$value = maybe_unserialize($value);
}

return $value;
}

Expand Down Expand Up @@ -101,9 +103,11 @@ public function get_visible_acf_fields($widget_id = null) {
'flexible_content',
'qtranslate_file',
'qtranslate_image',
'qtranslate_post_object',
'qtranslate_text',
'qtranslate_textarea',
'qtranslate_wysiwyg'
'qtranslate_url',
'qtranslate_wysiwyg',
);

foreach (acf_get_field_groups($filter) as $field_group) {
Expand Down
24 changes: 12 additions & 12 deletions src/acf_5/fields/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class acf_qtranslate_acf_5_image extends acf_field_image {
*/
protected $plugin;


/*
* __construct
*
Expand All @@ -31,18 +32,17 @@ function __construct($plugin) {
}

/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/

* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {

// vars
Expand Down
Loading

0 comments on commit d6121ab

Please sign in to comment.