Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F115220335
PhabricatorTokenizerEditField.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, May 30, 13:32
Size
2 KB
Mime Type
text/x-php
Expires
Sun, Jun 1, 13:32 (2 d)
Engine
blob
Format
Raw Data
Handle
26458759
Attached To
rPH Phabricator
PhabricatorTokenizerEditField.php
View Options
<?php
abstract
class
PhabricatorTokenizerEditField
extends
PhabricatorEditField
{
private
$originalValue
;
abstract
protected
function
newDatasource
();
protected
function
newControl
()
{
$control
=
id
(
new
AphrontFormTokenizerControl
())
->
setDatasource
(
$this
->
newDatasource
());
if
(
$this
->
originalValue
!==
null
)
{
$control
->
setOriginalValue
(
$this
->
originalValue
);
}
return
$control
;
}
public
function
setValue
(
$value
)
{
$this
->
originalValue
=
$value
;
return
parent
::
setValue
(
$value
);
}
protected
function
getValueFromSubmit
(
AphrontRequest
$request
,
$key
)
{
// TODO: Maybe move this unusual read somewhere else so subclassing this
// correctly is easier?
$this
->
originalValue
=
$request
->
getArr
(
$key
.
'.original'
);
return
parent
::
getValueFromSubmit
(
$request
,
$key
);
}
protected
function
getValueForTransaction
()
{
$new
=
parent
::
getValueForTransaction
();
$edge_types
=
array
(
PhabricatorTransactions
::
TYPE_EDGE
=>
true
,
PhabricatorTransactions
::
TYPE_SUBSCRIBERS
=>
true
,
);
if
(
isset
(
$edge_types
[
$this
->
getTransactionType
()]))
{
if
(
$this
->
originalValue
!==
null
)
{
// If we're building an edge transaction and the request has data
// about the original value the user saw when they loaded the form,
// interpret the edit as a mixture of "+" and "-" operations instead
// of a single "=" operation. This limits our exposure to race
// conditions by making most concurrent edits merge correctly.
$new
=
parent
::
getValueForTransaction
();
$old
=
$this
->
originalValue
;
$add
=
array_diff
(
$new
,
$old
);
$rem
=
array_diff
(
$old
,
$new
);
$value
=
array
();
if
(
$add
)
{
$value
[
'+'
]
=
array_fuse
(
$add
);
}
if
(
$rem
)
{
$value
[
'-'
]
=
array_fuse
(
$rem
);
}
return
$value
;
}
else
{
if
(!
is_array
(
$new
))
{
throw
new
Exception
(
print_r
(
$new
,
true
));
}
return
array
(
'='
=>
array_fuse
(
$new
),
);
}
}
return
$new
;
}
protected
function
newHTTPParameterType
()
{
return
new
AphrontPHIDListHTTPParameterType
();
}
}
Event Timeline
Log In to Comment