![]() Lofi_feeds_ name: lofi Feeds Importĭescription: Import nodes from external feeds modules/custom/lofi_feeds_import/. Add two files there, lofi_feeds_ and lofi_feeds_. Create a new directory for your module in your installation's modules directory. To run this code from bash using drush, we have to create a little custom module that wraps around our code. Maybe this has to do with timezone settings of that field. As mentioned in the code, I couldn't find a way to attach the time zone in the date string. The $strDateFormatted variable should hold the date string in proper format now. ![]() $strDateFormatted = \Drupal::service('date.formatter')->format($timestamp, 'custom', 'Y-m-d\TH:i:s', drupal_get_user_timezone()) $timestamp = $objVeranstaltungsDatum->getTimestamp() $objVeranstaltungsDatum->sub(DateInterval::createFromDateString('60 minutes')) I couldn't manage to include the timezone in our datestring, so we do it this way :( $objVeranstaltungsDatum = DateTime::createFromFormat("d.m.Y - H:i", $strDatum) create datetime object from supplied date string $strDatum = $entry->Datum //date string from XML source ie. Let's go back to our import function and see what this would look like in PHP: $content = file_get_contents($feed_source) If your content type on the other hand uses a datefield with date and time, your string format would be Y-m-d\TH:i:s, which translates to something like T23:30:00. If it's a date-only field, the right format would be Y-m-d which translates to something like. The right type depends on the field settings of your content type. If your new node type contains a date field, you need to make sure, that you convert the date read from the XML source to the right date format for your new node. Make sure you use the right formatted date string when. 'langcode' => 'de', //holds the language code 'created' => 'optional: properly formatted date string for custom creation date' ![]() 'uid' => 0, //the id of the user that owns this node. ![]() 'type' => 'your_custom_nodetype', //machine name found at /admin/structure/types In our example this would be $entry->Datum, $entry->Titel and $entry->Bodyĭrush_print('creating new node: '. the $entry object holds all fields from our tag in the XML source. The code that reads XML and creates new nodes looks someting like that: //$feed_source is the full url of our xml source file $content = file_get_contents($feed_source)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |