|
|
## 1.Process plugins 插件
|
|
|
1. 用于对提取到的source字段数据进行转换处理
|
|
|
2. 转换处理可以使用下列插件标识符表达式进行相关操作,得到自己想要的数据形式
|
|
|
|
|
|
## 2.Porcess plugins 表达式
|
|
|
|
|
|
### 2.1. get
|
|
|
1. 获取某一个source字段的值
|
|
|
2. 例: name: "zhang san" 结果:zhang san
|
|
|
3. 表达式:
|
|
|
```
|
|
|
field_text // 自定义名称
|
|
|
plugin: get
|
|
|
source: name // 你自己在source里配置的自动名称
|
|
|
```
|
|
|
|
|
|
### 2.2.str_replace
|
|
|
1. 用一个字符替换成另外一个值
|
|
|
2. 例: text: "hello world", 结果:"hi hello world"
|
|
|
3. 表达式:
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: str_replace
|
|
|
source: text
|
|
|
search: hello
|
|
|
replace: hi hello
|
|
|
```
|
|
|
|
|
|
## 2.3.array_shift
|
|
|
1. 函数删除数组中第一个元素,并返回被删除元素的值
|
|
|
2. 例: authors: [a,b,c], 结果:a
|
|
|
3. 表达式:
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: array_shift
|
|
|
source: authors
|
|
|
```
|
|
|
|
|
|
## 2.4.array_pop
|
|
|
1. 删除数组中的最后一个元素
|
|
|
2. 例: text: [a,b,c], 结果:c
|
|
|
3. 表达式:
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: array_pop
|
|
|
source: authors
|
|
|
```
|
|
|
## 2.5.array_build
|
|
|
1. 把数组的值,重新组成一个新的数组,新数组的key和value来自的之前的数组value
|
|
|
2. 例:
|
|
|
```
|
|
|
// languages:
|
|
|
[["language"=>"en","domain"=>"http://example.com"],["language"=>"fr","domain"="http://fr.example.com"]]
|
|
|
//结果:
|
|
|
["en"=>"http://example.com","fr"=>"http://fr.example.com"]
|
|
|
```
|
|
|
|
|
|
3. 表达式:
|
|
|
```
|
|
|
domains:
|
|
|
plugin: array_build
|
|
|
key: language
|
|
|
value: domain
|
|
|
source: languages
|
|
|
```
|
|
|
## 2.5.callback
|
|
|
1. 调用php的基本函数 或者自定义韩式
|
|
|
2. 表达式:
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: callback
|
|
|
source: authors
|
|
|
callable: strtolower //支持同时多个函数 ["\Drupal\Component\Utility\Unicode","strtolower"]
|
|
|
```
|
|
|
## 2.5.default_value
|
|
|
1. 不从source里取值,直接定一个默认值
|
|
|
2. 例子:
|
|
|
3. 表达式:
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: default_value
|
|
|
default_value: hello
|
|
|
strict: // 可选项
|
|
|
- FALSE // input value is empty(). 显示hello
|
|
|
- TRUE //input value is NULL. 显示hello
|
|
|
```
|
|
|
## 2.6 concat
|
|
|
1. 从source里提取几个字段的值,然后组合起来,并可以用自定义的分隔符号分开
|
|
|
2. 例:first_name = json,last_name=xml, 结果:json/xml
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: concat
|
|
|
source:
|
|
|
- first_name
|
|
|
- last_name
|
|
|
delimiter: /
|
|
|
|
|
|
```
|
|
|
|
|
|
## 2.7.single_value
|
|
|
1. 如果source字段值是一个数组,作为一个变量传入到下面要执行的函数里
|
|
|
2. 例子:authors: "json,xml", 生成一个数组[json,xml],用single_value后的效果,这个[json,xml]作为一个变量传入text_funs里
|
|
|
```
|
|
|
field_text:
|
|
|
-
|
|
|
plugin: explode
|
|
|
source: authors
|
|
|
delimiter: ','
|
|
|
-
|
|
|
plugin: single_value
|
|
|
-
|
|
|
plugin: text_funs
|
|
|
```
|
|
|
|
|
|
## 2.8.multiple_values
|
|
|
1. 如果source字段值是一个数组,作为多个变量传入要执行的函数里,和上例子相反操作,变量做过多个值传入
|
|
|
2. 例:数组["json","xml"], 结果: ["JSON","XML"]
|
|
|
```
|
|
|
field_text:
|
|
|
-
|
|
|
plugin: get
|
|
|
source: authors
|
|
|
-
|
|
|
plugin: multiple_values
|
|
|
-
|
|
|
plugin: callback
|
|
|
callable: strtoupper
|
|
|
|
|
|
|
|
|
```
|
|
|
## 2.9.explode
|
|
|
1. 把文本分割成数组
|
|
|
2. 例:字符串:"hi,xml,json",结果:数组 ["hi","xml","json"]
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: explode
|
|
|
source: authors
|
|
|
delimiter: ','
|
|
|
|
|
|
```
|
|
|
## 2.10 extract
|
|
|
1. 如果source字段值是一个数组,可以用定义索引继续提取其中的值,支持默认值
|
|
|
2. 表达式
|
|
|
- 返回$source['some_text_field']['und'][0]['value']的值
|
|
|
```
|
|
|
|
|
|
field_text:
|
|
|
plugin: extract
|
|
|
source: authors
|
|
|
index
|
|
|
- und
|
|
|
- 0
|
|
|
- value
|
|
|
```
|
|
|
- 如果 $source['authors']['title'] 不存在返回"Default title"
|
|
|
```
|
|
|
|
|
|
field_text:
|
|
|
plugin: extract
|
|
|
source: authors
|
|
|
default:'Default title'
|
|
|
index
|
|
|
- title
|
|
|
```
|
|
|
## 2.11 flatten
|
|
|
1. 多位数组,全部转换成一维度数组
|
|
|
2. 例:[[1, 2, [3, 4]], [5], 6] 变成 [1, 2, 3, 4, 5, 6].
|
|
|
3. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
-
|
|
|
plugin: default_value
|
|
|
source: authors
|
|
|
default_value: "[[1, 2, [3, 4]], [5], 6]"
|
|
|
-
|
|
|
plugin: flatten
|
|
|
|
|
|
```
|
|
|
## 2.12 format_date
|
|
|
1. 格式化时间
|
|
|
2. 表达式:
|
|
|
```
|
|
|
field_time:
|
|
|
plugin: format_date
|
|
|
from_format: 'Y-m-d\TH:i:sO'
|
|
|
to_format: 'Y-m-d\TH:i:s'
|
|
|
from_timezone: 'America/Managua' //可选
|
|
|
to_timezone: 'UTC' //可选
|
|
|
settings: //可选
|
|
|
validate_format: false//可选
|
|
|
source: event_time
|
|
|
```
|
|
|
## 2.13. machine_name
|
|
|
1. 转换成机器名,支持汉字转换拼音
|
|
|
2. 例1:张山 结果:zhangshan 例2: hello world 结果:hello_world
|
|
|
3. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: machine_name
|
|
|
source: authors
|
|
|
```
|
|
|
|
|
|
## 2.14 null_coalesce
|
|
|
1. 给定插件提供的一组值,插件将返回第一个非空值
|
|
|
2. 等同于 `foo ?? bar ?? baz`
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: null_coalesce
|
|
|
source: authors
|
|
|
- foo
|
|
|
- bar
|
|
|
- baz
|
|
|
default_value: hee //可选 ,如果所有值都是NULL,指定一个默认值
|
|
|
```
|
|
|
## 2.15 skip_on_empty
|
|
|
1. 如果当前值未空 (empty string, NULL, FALSE, 0, '0', or an empty array). skipped
|
|
|
2. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: skip_on_empty
|
|
|
method: row //Skips the entire row when an empty value is encountered.
|
|
|
source: authors
|
|
|
message: 'Field field_name is missing'
|
|
|
```
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: skip_on_empty
|
|
|
method: process //Prevents further processing of the input property when the value is empty.
|
|
|
source: authors
|
|
|
message: 'Field field_name is missing'
|
|
|
```
|
|
|
## 2.16 skip_row_if_not_set
|
|
|
1. 如果source字段value不存在,skip
|
|
|
2. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: skip_row_if_not_set
|
|
|
source: authors
|
|
|
```
|
|
|
## 2.17 static_map
|
|
|
1. 根据source字段的值判断是否存在,然后返回自定的数值
|
|
|
2. 例:如果authors 值等于from,转换成to,如果是this,转换成that
|
|
|
3. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: static_map
|
|
|
source: authors
|
|
|
map:
|
|
|
from: to
|
|
|
this: that
|
|
|
bypass: TRUE // 选项,如果没有找到匹配,比如authors等于json,直接返回json
|
|
|
```
|
|
|
3. 如果 authors = filter and name = 2 返回 xml
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: static_map
|
|
|
source:
|
|
|
- authors
|
|
|
- name
|
|
|
map:
|
|
|
filter:
|
|
|
1: json
|
|
|
2: xml
|
|
|
3: php
|
|
|
php
|
|
|
1: obj
|
|
|
```
|
|
|
## 2.18 substr
|
|
|
1. 函数返回字符串的一部分
|
|
|
2. 等同于php substr($source['field_text'], 1, 5);
|
|
|
3. authors = "jsontext", 返回: sonte
|
|
|
4. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: substr
|
|
|
source: authors
|
|
|
start: 1
|
|
|
length: 5
|
|
|
```
|
|
|
## 2.19 urlencode
|
|
|
1. 转码
|
|
|
2. 'http://example.com/a url with spaces.html' 转换结果 'http://example.com/a%20url%20with%20spaces.html'.
|
|
|
3. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: array_shift
|
|
|
source: 'http://example.com/a url with spaces.html'
|
|
|
```
|
|
|
## 2.20 convert_tokens [保留] 系统本身直接支持token
|
|
|
1. 支持token,把token转换正常的值
|
|
|
2. 把 !site 转换成token格式[site:name]格式
|
|
|
3. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: convert_tokens
|
|
|
source: authors
|
|
|
```
|
|
|
|
|
|
## 2.21 download
|
|
|
1. 通过 HTTP(S) 远程下载文件到本地文件系统
|
|
|
2. - source URL, e.g. 'http://www.example.com/img/foo.img'
|
|
|
- destination URI, e.g. 'public://images/foo.img'
|
|
|
3. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: download
|
|
|
source:
|
|
|
- source_url
|
|
|
- destination_uri
|
|
|
file_exists: rename // replace , use existing
|
|
|
guzzle_options: // "http://docs.guzzlephp.org/en/latest/request-options.html Array of request options for Guzzle"
|
|
|
```
|
|
|
|
|
|
## 2.22 entity_generate
|
|
|
1. 创建一个实体
|
|
|
2. 表达式
|
|
|
```
|
|
|
process:
|
|
|
type:
|
|
|
plugin: default_value
|
|
|
default_value: page
|
|
|
foo: bar
|
|
|
field_tags:
|
|
|
plugin: entity_generate // 自动创建一个实体
|
|
|
source: tags //数据来源
|
|
|
default_values: //默认值
|
|
|
description: Default description
|
|
|
values: //这个实体其他字段的值
|
|
|
field_long_description: some_source_field
|
|
|
field_foo: '@foo' // 应用自己定义的变量
|
|
|
```
|
|
|
|
|
|
## 2.23 entity_lookup
|
|
|
1. 查找一个实体,返回结果
|
|
|
2. 表达式
|
|
|
```
|
|
|
field_tags:
|
|
|
plugin: entity_lookup
|
|
|
source: tags
|
|
|
value_key: name // 从source获取到tags和taxonomy_term name对比,如果找到了返回vid
|
|
|
bundle_key: vid
|
|
|
bundle: tags
|
|
|
entity_type: taxonomy_term
|
|
|
ignore_case: true
|
|
|
```
|
|
|
|
|
|
## 2.24 entity_exists
|
|
|
1. 判断一个实体是否存在,如果存在返回实体id,不存在返回false
|
|
|
2. 表达式
|
|
|
```
|
|
|
field_tags:
|
|
|
plugin: entity_exists
|
|
|
source: tid
|
|
|
entity_type: taxonomy_term
|
|
|
```
|
|
|
|
|
|
## 2.25 default_entity_value
|
|
|
1. 定义默认实体的值
|
|
|
2. 表达式
|
|
|
```
|
|
|
uid:
|
|
|
plugin: default_entity_value
|
|
|
entity_type: user
|
|
|
value_key: name
|
|
|
ignore_case: true
|
|
|
default_value: editorial // 如果未空,返回默认值
|
|
|
```
|
|
|
|
|
|
## 2.26 skip_on_value
|
|
|
1. If the source evaluates to a configured value, skip processing or whole row.
|
|
|
2. 表达式
|
|
|
```
|
|
|
type:
|
|
|
plugin: skip_on_value
|
|
|
not_equals: true
|
|
|
source: content_type
|
|
|
method: row
|
|
|
value: // 当content type 不等于 article 或者 testimonial 跳出整个row
|
|
|
- article
|
|
|
- testimonial
|
|
|
```
|
|
|
|
|
|
```
|
|
|
type:
|
|
|
plugin: skip_on_value
|
|
|
source: content_type
|
|
|
method: process // 阻止下一步进程
|
|
|
value: blog
|
|
|
```
|
|
|
|
|
|
## 2.27 dom_extract
|
|
|
1. 提取html中的内容
|
|
|
2. attribute 值 text 表示获取元素里全部文本信息,html 表示获取全部html内容,src 获取未src里的值。其他属性根据html里面的具体属性变量获取
|
|
|
3. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: dom_extract
|
|
|
source: text
|
|
|
selector: td > a // 用css选取内容
|
|
|
attribute: href // 获取选取内容里面的具体属性 多个属性使用如: ["href","title","a"]
|
|
|
```
|
|
|
|
|
|
## 2.28 json_extract
|
|
|
1. json 数据的提取
|
|
|
2. 参考 https://jmespath.org/tutorial.html 变量使用规则
|
|
|
3. 表达式
|
|
|
```
|
|
|
field_text:
|
|
|
plugin: json_extract
|
|
|
source: text
|
|
|
selector: entities.0 //选取 entities 数组 key等于0的 数据,表达式参考指南
|
|
|
```
|
|
|
## 2.29 dom
|
|
|
1. dom
|
|
|
2. 表达式
|
|
|
```
|
|
|
body/value:
|
|
|
-
|
|
|
plugin: dom
|
|
|
method: import
|
|
|
source: 'body/0/value'
|
|
|
-
|
|
|
plugin: dom
|
|
|
method: export
|
|
|
```
|
|
|
|
|
|
```
|
|
|
process:
|
|
|
'body/value':
|
|
|
-
|
|
|
plugin: dom
|
|
|
method: import
|
|
|
source: 'body/0/value'
|
|
|
non_root: true
|
|
|
log_messages: true
|
|
|
version: '1.0'
|
|
|
encoding: UTF-8
|
|
|
-
|
|
|
plugin: dom
|
|
|
method: export
|
|
|
non_root: true
|
|
|
```
|
|
|
|
|
|
|
|
|
## 2.30 dom_apply_styles
|
|
|
1. 接受 dom 样式
|
|
|
2. 表达式
|
|
|
```
|
|
|
'body/value':
|
|
|
-
|
|
|
plugin: dom
|
|
|
method: import
|
|
|
source: 'body/0/value'
|
|
|
-
|
|
|
plugin: dom_apply_styles
|
|
|
format: full_html
|
|
|
rules:
|
|
|
-
|
|
|
xpath: '//b'
|
|
|
style: Bold
|
|
|
-
|
|
|
xpath: '//span/i'
|
|
|
style: Italic
|
|
|
depth: 1
|
|
|
-
|
|
|
plugin: dom
|
|
|
method: export
|
|
|
```
|
|
|
## 2.31 dom_str_replace
|
|
|
1. dom 字符串替换
|
|
|
2. 表达式
|
|
|
```
|
|
|
'body/value':
|
|
|
-
|
|
|
plugin: dom
|
|
|
method: import
|
|
|
source: 'body/0/value'
|
|
|
-
|
|
|
plugin: dom_str_replace
|
|
|
mode: attribute
|
|
|
xpath: '//a'
|
|
|
attribute_options:
|
|
|
name: href
|
|
|
search: 'foo'
|
|
|
replace: 'bar'
|
|
|
-
|
|
|
plugin: dom_str_replace
|
|
|
mode: attribute
|
|
|
xpath: '//a'
|
|
|
attribute_options:
|
|
|
name: href
|
|
|
regex: true
|
|
|
search: '/foo/'
|
|
|
replace: 'bar'
|
|
|
-
|
|
|
plugin: dom
|
|
|
method: export
|
|
|
``` |
|
|
\ No newline at end of file |