Skip to content
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

Producers for Taxonomy terms and Menu items #9

Open
ivanchaer opened this issue Mar 3, 2016 · 16 comments
Open

Producers for Taxonomy terms and Menu items #9

ivanchaer opened this issue Mar 3, 2016 · 16 comments

Comments

@ivanchaer
Copy link

Hi Antonio,

I'm interested in implementing a taxonomy term producer and a menu item producer.
Any tips and insights on how to approach this task are most welcome.

Regarding taxonomies, I noticed that besides the NodeProducer class, the Integration Producer module also has a TaxonomyTermProducer class.

I'm wondering if there is a way to adapt the Producer example by configuring the ProducerFactory to use the taxonomy_term_producer instead of the default node_producer, or if I should proceed in a different way.

Any help will be much appreciated.

Many thanks,
Ivan

@ademarco
Copy link
Member

ademarco commented Mar 3, 2016

You are right, I started implementing the taxonomy term producer but never finished since it was out of our scope.

You can try to create a taxonomy term producer and report here the issues you encounter.

@ademarco
Copy link
Member

ademarco commented Mar 3, 2016

To answer your question actually ProducerFactory::create() accepts a second argument where you could set the producer plugin, such as:

$producer = ProducerFactory::create('tags', 'taxonomy_term_producer')
  ->setBackend('filesystem')
  ->setEntityBundle('tags')
  ->setResourceSchema('tags')
  ->setMapping('name', 'name');

You can try if this works as well.

@ademarco
Copy link
Member

ademarco commented Mar 3, 2016

Actually this works, I've tested it, just creation and update dates are empty since this information is not present on the term itself in Drupal to start with:

BackendFactory::create('backend', 'memory_backend')->setResourceSchema('article');
ResourceSchemaFactory::create('tag')->setField('name', 'Name');

$tag_producer = ProducerFactory::create('tag', 'taxonomy_term_producer')
  ->setBackend('backend')
  ->setEntityBundle('tags')
  ->setResourceSchema('tag')
  ->setMapping('name', 'name');

$term = taxonomy_term_load(1);
$tag = $tag_producer->build($term);

@ivanchaer
Copy link
Author

Thanks a lot Antonio, that's really great.
I had to make the taxonomies translatable for some reason, as before doing that, I was getting an error related to trying to use "und" as the default language (sorry, I don't have the exact error message anymore). I wonder if it has any relation to the issue 4.
Anyway, it's good now. Next I will try to do the producer for menu items. I'll let you know how it goes.

@ademarco
Copy link
Member

ademarco commented Mar 3, 2016

That error message you got on the UI or using the API?

@ivanchaer
Copy link
Author

Using the API.
I'm not sure how to do it with the UI. How does it go?
Thanks!

@ivanchaer
Copy link
Author

Good morning Antonio,

I rolled back the changes to the db, and re-ran the taxonomy term export, in order to get the error message back, in case it might be useful to you:

WD php: Exception: Trying to set a not-available language as current language: und in Drupal\integration\Document\Document->setCurrentLanguage() (line 157 of [error]
/(...)/sites/all/modules/contrib/integration/src/Document/Document.php).

The taxonomies that I'm exporting have custom fields, which are at this moment set to non translatable. What is weird is that it manages to export quite a lot of terms from the same taxonomy before running into the specific term that throws the error.

I'm curious about the UI way. I couldn't find it yet. If you tell me where to start on the UI, I can probably find my way.

Thanks for all the help!

@ademarco
Copy link
Member

ademarco commented Mar 4, 2016

Can you post here the API calls you use to create the export?

On Fri, Mar 4, 2016 at 10:44 AM, Ivan Chaer [email protected]
wrote:

Good morning Antonio,

I rolled back the changes to the db, and re-ran the taxonomy term export,
in order to get the error message back, in case it might be useful to you:

WD php: Exception: Trying to set a not-available language as current
language: und in Drupal\integration\Document\Document->setCurrentLanguage()
(line 157 of [error]
/(...)/sites/all/modules/contrib/integration/src/Document/Document.php).

The taxonomies that I'm exporting have custom fields, which are at this
moment set to non translatable. What is weird is that it manages to export
quite a lot of terms from the same taxonomy before running into the
specific term that throws the error.

I'm curious about the UI way. I couldn't find it yet. If you tell me where
to start on the UI, I can probably find my way.

Thanks for all the help!


Reply to this email directly or view it on GitHub
#9 (comment)
.

@ivanchaer
Copy link
Author

I'm using a loop to export all terms from all taxonomies, but I can get the same error if I just run your example on the term id that throws the error (1146):

use Drupal\integration_producer\ProducerFactory;
use Drupal\integration\Backend\BackendFactory;
use Drupal\integration\ResourceSchema\ResourceSchemaFactory;

BackendFactory::create('backend', 'memory_backend')->setResourceSchema('article');
ResourceSchemaFactory::create('tag')->setField('name', 'Name');

$tag_producer = ProducerFactory::create('tag', 'taxonomy_term_producer')
  ->setBackend('backend')
  ->setEntityBundle('tags')
  ->setResourceSchema('tag')
  ->setMapping('name', 'name');

$term = taxonomy_term_load(1146);
$tag = $tag_producer->build($term);

@ademarco
Copy link
Member

ademarco commented Mar 4, 2016

That's wicked... could you paste a var_export($term); for the killer term too?

@ivanchaer
Copy link
Author

Indeed! :D
There you go:

stdClass::__set_state(array(
   'tid' => '1146',
   'vid' => '3',
   'name' => 'Transport infographics',
   'description' => '',
   'format' => 'full_html',
   'weight' => '7',
   'uuid' => '61f0a207-2353-4aaf-8953-eeb0c0c9dfa5',
   'language' => 'und',
   'i18n_tsid' => '0',
   'vocabulary_machine_name' => 'transport_categories',
   'field_internal_id' => 
  array (
    'und' => 
    array (
      0 => 
      array (
        'value' => 'transport-infographics',
        'format' => NULL,
        'safe_value' => 'transport-infographics',
      ),
    ),
  ),
   'field_tr_site_section' => 
  array (
    'und' => 
    array (
      0 => 
      array (
        'value' => 'facts-fundings',
        'format' => NULL,
        'safe_value' => 'facts-fundings',
      ),
    ),
  ),
   'translations' => 
  stdClass::__set_state(array(
     'original' => 'en',
     'data' => 
    array (
      'en' => 
      array (
        'entity_type' => 'taxonomy_term',
        'entity_id' => '1146',
        'revision_id' => '1146',
        'language' => 'en',
        'source' => '',
        'uid' => '1',
        'status' => '1',
        'translate' => '0',
        'created' => '1455713063',
        'changed' => '1455713063',
      ),
    ),
  )),
   'rdf_mapping' => 
  array (
    'rdftype' => 
    array (
      0 => 'skos:Concept',
    ),
    'name' => 
    array (
      'predicates' => 
      array (
        0 => 'rdfs:label',
        1 => 'skos:prefLabel',
      ),
    ),
    'description' => 
    array (
      'predicates' => 
      array (
        0 => 'skos:definition',
      ),
    ),
    'vid' => 
    array (
      'predicates' => 
      array (
        0 => 'skos:inScheme',
      ),
      'type' => 'rel',
    ),
    'parent' => 
    array (
      'predicates' => 
      array (
        0 => 'skos:broader',
      ),
      'type' => 'rel',
    ),
  ),
   'path' => 
  array (
    'pathauto' => '1',
  ),
))

@ivanchaer
Copy link
Author

And this is a term that was exported without problems:

stdClass::__set_state(array(
   'tid' => '1188',
   'vid' => '3',
   'name' => 'ten-t-days-2010',
   'description' => NULL,
   'format' => NULL,
   'weight' => '0',
   'uuid' => '1f3aa50d-837e-4bc2-8447-5279e6ece4ff',
   'language' => 'und',
   'i18n_tsid' => '0',
   'vocabulary_machine_name' => 'transport_categories',
   'field_internal_id' => 
  array (
  ),
   'field_tr_site_section' => 
  array (
  ),
   'translations' => 
  stdClass::__set_state(array(
     'original' => 'und',
     'data' => 
    array (
      'und' => 
      array (
        'entity_type' => 'taxonomy_term',
        'entity_id' => '1188',
        'revision_id' => '1188',
        'language' => 'und',
        'source' => '',
        'uid' => '1',
        'status' => '1',
        'translate' => '0',
        'created' => '1456407817',
        'changed' => '1456407817',
      ),
    ),
  )),
   'rdf_mapping' => 
  array (
    'rdftype' => 
    array (
      0 => 'skos:Concept',
    ),
    'name' => 
    array (
      'predicates' => 
      array (
        0 => 'rdfs:label',
        1 => 'skos:prefLabel',
      ),
    ),
    'description' => 
    array (
      'predicates' => 
      array (
        0 => 'skos:definition',
      ),
    ),
    'vid' => 
    array (
      'predicates' => 
      array (
        0 => 'skos:inScheme',
      ),
      'type' => 'rel',
    ),
    'parent' => 
    array (
      'predicates' => 
      array (
        0 => 'skos:broader',
      ),
      'type' => 'rel',
    ),
  ),
))

@ademarco
Copy link
Member

ademarco commented Mar 4, 2016

The problem is with the original language being en while Document object tries to set und, you say the taxonomy terms are translatable via entity translation right?

@ivanchaer
Copy link
Author

No, for now the taxonomies are set to:

No multilingual options for terms. Only the vocabulary will be translatable.

When I made it translatable yesterday evening, the error went away. I rolled back the db today as you were interested in the error message, but it's ok for me to make them translatable.

@ademarco
Copy link
Member

ademarco commented Mar 4, 2016

Ah ok I see, that's good to know. Thanks!

On Fri, Mar 4, 2016 at 11:19 AM, Ivan Chaer [email protected]
wrote:

No, for now the taxonomies are set to:

No multilingual options for terms. Only the vocabulary will be
translatable.

When I made it translatable yesterday evening, the error went away. I
rolled back the db today as you were interested in the error message, but
it's ok for me to make them translatable.


Reply to this email directly or view it on GitHub
#9 (comment)
.

@ivanchaer
Copy link
Author

After struggling with trying to create a producer for menu links, I got under the impression that the Integration module focus on exporting entities (like nodes and taxonomies), but that perhaps it wouldn't be suited to export menu items. Am I wrong?

Btw, I found the producer UI url just recently, while reading the code:
/admin/config/integration/produce

Foolish, I didn't think of looking into config... Maybe would be good to add to this url to the producer documentation? (I was going to open a new issue for this, but since I mentioned this previously on this issue, I just added it here. Let me know if you prefer to make a new issue on Github for this.)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants